GridDesktop ın Bağlam Menüsünü Yönetme

Giriş

ContextMenuManager sınıfı, bağlam menü öğelerini yönetmek için kullanılır. GridDesktop.ContextMenuManager özniteliği, ContextMenuManager nesnesinin örneğini alır. Örneğin, ContextMenuManager.MenuItemAvailable_Copy özniteliği, bağlam menü öğesi Kopyala‘nın mevcut olup olmadığını belirten bir değer alır veya bu değeri ayarlar. Benzer şekilde, farklı bağlam menü öğeleri için tüm karşılık gelen özniteliklere sahibiz.

ÖNEMLİ: Varsayılan olarak, tüm bağlam menü öğeleri listede görünür.

Bağlam Menüsünü Yönetme

Bağlam Menü Öğelerini Gizleme

Bu görevi gerçekleştirmek için öncelikle GridDesktop’un varsayılan bağlam menüsüne bakalım.

GridDeskop’un varsayılan menüsü

todo:image_alt_text

Şimdi, aşağıdaki kodu kullanarak bazı menü öğelerini gizleyin:

// 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;

Yukarıdaki kodu çalıştırdıktan sonra, bazı menü öğeleri kullanıcılar için görünmez olacaktır:

Bazı menü öğeleri gizlendi

todo:image_alt_text

Yeni Menü Öğeleri Ekleme

Aşağıdaki kod parçasını kullanarak listeye yeni bir bağlam menü öğesi ekleyin.

// 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);

Ayrıca, yeni komut/seçenek için bir etkinlik yöneticisi belirtiyoruz.

// 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);
}

Yukarıdaki kodu çalıştırdıktan sonra, bağlam menüsünde yeni bir menü öğesi görünebilir. Bir hücre tıklandığında ayrıca bir ileti de görünecektir.

Listeye yeni bir menü öğesi eklendi

todo:image_alt_text