A newer version of this page is available. Switch to the current version.

Context Menus

  • 3 minutes to read

The GridControl can display popup menus that enable an end-user to manage data (apply grouping and sorting, display summaries, etc.) and customize a View by showing and hiding its UI elements. All these menus can be customized. For example, you can remove existing menu items and/or add new items.

Context Menus Overview

Use the GridViewBase.GridMenu property to obtain the context menu currently being displayed within a View.

Menu Type

Description

Availability

Image

Group Panel

This menu is shown when an end-user right-clicks within the Group Panel.

GridViewBase.IsGroupPanelMenuEnabled

GridMenuType_GroupPanel

Column

This menu is shown when an end-user right-clicks a column header.

DataViewBase.IsColumnMenuEnabled

GridMenuType_Column

Row Cell

This menu is shown when an end-user right-clicks a data cell. You should manually create this menu.

For an example, see How to: Display a Context Menu for Data Cells.

DataViewBase.IsRowCellMenuEnabled

GridMenuType_Cell

Summary

This menu is shown when an end-user right-clicks within the Summary Panel.

DataViewBase.IsTotalSummaryMenuEnabled

GridMenuType_Summary

Fixed Summary

This menu is shown when an end-user right-clicks within the Fixed Summary Panel.

DataViewBase.IsTotalSummaryMenuEnabled

fixedsummarycontextmenu

To obtain the current column, view or grid, use the dxg:GridPopupMenu.GridMenuInfo attached property.

GridControl displays specific context menus in Compact Mode.

Customizing Context Menus

Change Menu Item Names

When customizing a menu (e.g. removing or moving default items), menu items are referred to by their names. Default menu item names are listed in DefaultColumnMenuItemNames and DefaultSummaryMenuItemNames.

Customize Menu Items in Code

Handle the DataViewBase.ShowGridMenu event to dynamically customize grid menus at runtime.

Add, Move, and Remove Menu Items

A View provides multiple properties that allow you to customize its context menus by adding new menu items or removing existing items. These properties return a BarManagerActionCollection object that provides multiple methods, used to manage menu items contained within a context menu:

Menu Type

Property

Group Panel

GridViewBase.GroupPanelMenuCustomizations

Column

DataViewBase.ColumnMenuCustomizations

Band

TableView.BandMenuCustomizations

Row Cell

DataViewBase.RowCellMenuCustomizations

Summary

DataViewBase.TotalSummaryMenuCustomizations

Group Row

GridViewBase.GroupRowMenuCustomizations

Compact Panel

TableView

TableView.CompactModeFilterElementMenuCustomizations

TableView.CompactModeFilterMergeElementMenuCustomizations

TableView.CompactModeSortElementMenuCustomizations

TreeListView

TreeListView.CompactModeFilterElementMenuCustomizations

TreeListView.CompactModeFilterMergeElementMenuCustomizations

TreeListView.CompactModeSortElementMenuCustomizations

NOTE

This feature is not available in DXTreeList when Hierarchical Data Templates are used.

Example 1: Add Menu Items

The following example demonstrates how to add a custom menu item to the context menu of a grid column. For this, it is necessary to add a corresponding bar item (e.g. BarCheckItem) to the DataViewBase.ColumnMenuCustomizations collection, and specify different item properties. Also, you can insert this item into a specific position by attaching the BarItemLinkActionBase.ItemLinkIndex property to it.

<dxg:TableView.ColumnMenuCustomizations>
    <dxb:BarCheckItem Name="checkItem1" Content="Checked" IsChecked="True" dxb:BarItemLinkActionBase.ItemLinkIndex="0" />
    <dxb:BarItemLinkSeparator dxb:BarItemLinkActionBase.ItemLinkIndex="1" />
</dxg:TableView.ColumnMenuCustomizations>

Example 2: Remove Menu Items

The following example demonstrates how to remove a specific item from the context menu, which is shown for the Total Summary panel. For this, the RemoveBarItemAndLinkAction object is added to the DataViewBase.TotalSummaryMenuCustomizations collection, and the name of the bar item is specified by the corresponding field of the DefaultSummaryMenuItemNames class.

<dxg:TableView.TotalSummaryMenuCustomizations>
    <dxb:RemoveBarItemAndLinkAction ItemName="{x:Static dxg:DefaultSummaryMenuItemNames.Customize}" />
</dxg:TableView.TotalSummaryMenuCustomizations>

Examples