إدارة قائمة سياق GridDesktops

مقدمة

تستخدم فئة ContextMenuManager لإدارة عناصر قائمة السياق. يحصل السمة GridDesktop.ContextMenuManager على مثيل من كائن ContextMenuManager. على سبيل المثال، تحصل السمة ContextMenuManager.MenuItemAvailable_Copy على قيمة تشير ما إذا كانت عنصر قائمة السياق نسخ متاحة أم لا. بالمثل، لدينا جميع السمات المقابلة لعناصر قائمة السياق المختلفة.

مهم: بشكل افتراضي، جميع عناصر قائمة السياق مرئية في القائمة.

إدارة قائمة السياق

إخفاء عناصر قائمة السياق

لأداء هذه المهمة، نلقي أولا نظرة على قائمة السياق الافتراضية التي يحتوي عليها GridDesktop.

قائمة GridDesktop الافتراضية

todo:image_alt_text

الآن، قم بإخفاء بعض عناصر القائمة باستخدام الكود التالي:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Get the ContextMenuManager
ContextMenuManager cmm = this.grdDataEntry.ContextMenuManager;
// Hide the Copy option in the context menu
cmm.MenuItemAvailable_Copy = false;
// Hide the InsertRow option in the context menu
cmm.MenuItemAvailable_InsertRow = false;
// Hide the Format Cell dialog box
cmm.MenuItemAvailable_FormatCells = false;

بعد تنفيذ الكود أعلاه، لن تكون بعض عناصر القائمة مرئية للمستخدمين:

تم إخفاء بعض عناصر القائمة

todo:image_alt_text

إضافة عناصر قائمة جديدة

أضف عنصر قائمة سياق جديد إلى القائمة باستخدام مقتطف الكود التالي.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Get the active worksheet
Worksheet sheet = grdDataEntry.GetActiveWorksheet();
// Set the total columns diaplyed in the grid
sheet.ColumnsCount = 15;
// Set the total rows displayed in the grid
sheet.RowsCount = 15;
// Define a new menu item and specify its event handler
MenuItem mi = new MenuItem("newMenuItem", new System.EventHandler(miClicked));
// Set the label
mi.Text = "New Item";
// Add the menu item to the GridDesktop's context menu
grdDataEntry.ContextMenu.MenuItems.Add(mi);

نحدد أيضًا معالج حدث للأمر/الخيار الجديد.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Event Handler for the new menu item
private void miClicked(object sender, EventArgs e)
{
MenuItem mi = (MenuItem)sender;
MessageBox.Show("miCliked: " + mi.Text);
}

بعد تشغيل الكود أعلاه ، يمكن رؤية عنصر قائمة جديد في قائمة السياق. سيظهر أيضًا رسالة عند النقر على الخلية.

تمت إضافة عنصر قائمة جديد إلى القائمة

todo:image_alt_text