Description:
I would like to customize the standard context menu which appears when I right click the grid. How this can be done?
Answer:
Below you will find some sample code which demonstrates how to create a new MenuItem and add it to the grid's FooterMenu. Note, its class structure does not allow you to identify the menu object that this item belongs to. So, we suggest that you use the Item's Tag property and save the menu to it. Here is some sample code:
Visual BasicPrivate Sub GridView1_PopupMenuShowing(ByVal sender As System.Object, _
ByVal e As DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs) Handles GridView1.ShowGridMenu
If e.MenuType <> DevExpress.XtraGrid.Views.Grid.GridMenuType.Summary Then Exit Sub
Dim footerMenu As DevExpress.XtraGrid.Menu.GridViewFooterMenu = CType(e.Menu, DevExpress.XtraGrid.Menu.GridViewFooterMenu)
Dim menuItem As New DevExpress.Utils.Menu.DXMenuItem("MyItem", New EventHandler(AddressOf MyMenuItem))
menuItem.Tag = e.Menu
footerMenu.Items.Add(menuItem)
End Sub
Private Sub MyMenuItem(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim Item As DevExpress.Utils.Menu.DXMenuItem = CType(sender, DevExpress.Utils.Menu.DXMenuItem)
Dim menu As DevExpress.XtraGrid.Menu.GridViewFooterMenu = CType(Item.Tag, DevExpress.XtraGrid.Menu.GridViewFooterMenu)
MessageBox.Show(menu.View.FocusedColumn.Caption)
End Sub
Besides, we suggest that you review the Implementing Custom Behavior for Popup Menus topic in the XtraGrid help and FixedColumns module of the GridMainDemo demo project.
See Also:
PopupMenuShowing
How to disable particular menu items in the default grid menus