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

Giriş

ContextMenuManager sınıfı, bağlam menüsü öğ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, Kopyala bağlam menüsü öğesinin kullanılabilir olup olmadığını gösteren bir değer alır veya ayarlar. Benzer şekilde, farklı bağlam menüsü öğeleri için karşılık gelen tüm özniteliklere sahibiz.

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

İçerik Menüsünü Yönetme

Bağlam Menüsü Öğelerini Gizleme

Bu görevi gerçekleştirmek için önce GridDesktop’un sahip olduğu varsayılan içerik menüsüne bir göz atacağız.

GridDeskop’un varsayılan menüsü

yapılacaklar:resim_alternatif_metin

Ş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 tarafından görülemez:

Bazı menü öğeleri gizlidir

yapılacaklar:resim_alternatif_metin

Yeni Menü Öğeleri Ekleme

Aşağıdaki kod parçacığını kullanarak listeye yeni bir bağlam menüsü öğ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 olay işleyicisi belirliyoruz.

// 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ülebilir. Hücre tıklandığında da bir mesaj görünecektir.

Listeye yeni bir menü öğesi eklendi

yapılacaklar:resim_alternatif_metin