GridMenuEventArgs Class
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v18.2.Core.dll
Declaration
To learn more, see Context Menus.
Example
The following example demonstrates how to customize the grid’s context menu at runtime. For instance this sample demonstrates how to remove the default ‘Show Column Chooser’ menu item from the Column Context Menu, and add a custom item instead.
For this, it is necessary to handle the DataViewBase.ShowGridMenu event. In the event handler, all modifications to the list of menu items can be done by changing the GridMenuEventArgs.Customizations collection. To remove a specific menu item along with its link, use the RemoveBarItemAndLinkAction instance, and to add a custom menu item, a new BarButtonItem object must be added to the e.Customizations collection.
<dxg:GridControl.View>
<dxg:TableView ShowGridMenu="TableView_ShowGridMenu" />
</dxg:GridControl.View>
private void TableView_ShowGridMenu(object sender, GridMenuEventArgs e) {
// Check whether this event was raised for a column's context menu.
if (e.MenuType != GridMenuType.Column) return;
// Remove the Column Chooser menu item.
e.Customizations.Add(new RemoveBarItemAndLinkAction() {
ItemName = DefaultColumnMenuItemNames.ColumnChooser });
// Create a custom menu item and add it to the context menu.
BarButtonItem bi = new BarButtonItem();
bi.Name = "customItem";
bi.Content = "Custom Item";
bi.ItemClick += new ItemClickEventHandler(customItem_ItemClick);
e.Customizations.Add(bi);
}
private void customItem_ItemClick(object sender, ItemClickEventArgs e) {
// Implement the custom action.
// ...
}
Private Sub TableView_ShowGridMenu(ByVal sender As Object, ByVal e As GridMenuEventArgs)
' Check whether this event was raised for a column's context menu.
If e.MenuType <> GridMenuType.Column Then
Return
End If
' Remove the Column Chooser menu item.
e.Customizations.Add(New RemoveBarItemAndLinkAction() _
With {.ItemName = DefaultColumnMenuItemNames.ColumnChooser})
' Create a custom menu item and add it to the context menu.
Dim bi As New BarButtonItem()
bi.Name = "customItem"
bi.Content = "Custom Item"
AddHandler bi.ItemClick, AddressOf customItem_ItemClick
e.Customizations.Add(bi)
End Sub
Private Sub customItem_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
' Implement the custom action.
' ...
End Sub
See Also