PopupMenuShowingEventArgs.Menu Property
Gets or sets the popup menu that is about to be displayed.
Namespace: DevExpress.XtraGrid.Views.Grid
Assembly: DevExpress.XtraGrid.v24.2.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
#Declaration
#Property Value
Type | Description |
---|---|
DevExpress. |
The menu that is about to be displayed. |
#Remarks
The Menu property allows you to add, remove, and customize items in the currently processed popup menu. To identify the type of the menu, use PopupMenuShowingEventArgs.MenuType.
The Data Grid does not display empty popup menus. Thus, if you remove all items from the menu, this menu will not be displayed after your PopupMenuShowing event handler is complete.
When you right-click within a row or group row, the Data Grid creates an empty menu and fires the PopupMenuShowing event (the event’s PopupMenuShowingEventArgs.MenuType parameter is set to Row). If you leave this menu intact (empty), it will not be displayed. To add new menu items to this and other menus, use the Menu.Items.Add method. See an example below.
To access the existing menu items, you can iterate through the Menu.Items collection, or use the Menu.Find and Menu.FindAll methods. To hide or remove certain menu items, use the Menu.Hide and Menu.Remove methods. When searching for a target menu item, you need to know the menu item identifier, which you can find by reading the item’s DXMenuItem.Tag property. You can also see the Menu Item Identifiers section below to learn the available menu item identifiers for the built-in menus.
#Menu Item Objects
The menu items can be the following objects:
- DXMenuItem - A regular button.
- DXSubMenuItem - A sub-menu.
- DXMenuCheckItem - A check button.
Use these objects’ settings to change item captions, images, visibility, enabled state, etc.
The DXMenuItem.Tag properties store the menu item identifiers for the default menu items.
When you create a custom menu item, use the item’s DXMenuItem.Tag property to store any custom data with which you may need to identify the item or process the item’s click event.
#Menu Item Identifiers
The four tables below show the menu item identifiers (contents of the DXMenuItem.Tag properties) in Data Grid’s built-in menus.
#Column Header Menu (DevExpress.XtraGrid.Menu.GridViewColumnMenu)
When handling the PopupMenuShowing and GridMenuItemClick events, you can identify this menu type using the e.MenuType event parameter, which is set to GridMenuType.Column
The Tag properties of the items in this menu can be the following objects:
DevExpress.XtraGrid.Localization.GridStringId
DevExpress.XtraEditors.Controls.StringId
DevExpress.XtraGrid.ColumnGroupInterval
Menu Item | Tag |
---|---|
Full Expand | DevExpress. |
Full Collapse | DevExpress. |
Sort Ascending | DevExpress. |
Sort Descending | DevExpress. |
Sort by Summary (sub-menu) | DevExpress. The Tag properties of this submenu’s items contain Grid |
Group By This Column | DevExpress. |
Un | DevExpress. |
Hide Group By Box | DevExpress. |
Show Group By Box | DevExpress. |
Split | DevExpress. |
Remove Split | DevExpress. |
Group Interval (sub-menu) | DevExpress. |
Day | DevExpress. |
Month | DevExpress. |
Year | DevExpress. |
Smart | DevExpress. |
Group Summary Editor… | DevExpress. |
Hide This Column | DevExpress. |
Column Chooser | DevExpress. |
Best Fit | DevExpress. |
Best Fit (all columns) | DevExpress. |
Filter Editor… | DevExpress. |
Show Find Panel | DevExpress. |
Hide Find Panel | DevExpress. |
Show Auto Filter Row | DevExpress. |
Hide Auto Filter Row | DevExpress. |
Conditional Formatting (sub-menu) | DevExpress. |
Highlight Cell Rules (sub-menu) | DevExpress. |
Greater Than… | DevExpress. |
Less Than… | DevExpress. |
Between… | DevExpress. |
Equal To… | DevExpress. |
Text that Contains… | DevExpress. |
A Date Occurring… | DevExpress. |
Custom Condition… | DevExpress. |
Top/Bottom Rules (sub-menu) | DevExpress. |
Top 10 Items… | DevExpress. |
Bottom 10 Items… | DevExpress. |
Unique/Duplicate Rules (sub-menu) | DevExpress. |
Unique Values… | DevExpress. |
Duplicate Values… | DevExpress. |
Manage Rules… | DevExpress. |
Show Footer | DevExpress. |
Hide Footer | DevExpress. |
#Group Panel Menu (DevExpress.XtraGrid.Menu.GridViewGroupPanelMenu)
When handling the PopupMenuShowing and GridMenuItemClick events, you can identify this menu type using the e.MenuType event parameter, which is set to GridMenuType.Group
The Tag properties of the items in this menu contain DevExpress.XtraGrid.Localization.GridStringId enumeration values.
Menu Item | Tag |
---|---|
Full Expand | DevExpress. |
Full Collapse | DevExpress. |
Clear Grouping | DevExpress. |
Hide Group By Box | DevExpress. |
Split | DevExpress. |
Remove Split | DevExpress. |
Important
The e.
method (PopupDevExpress.
as a parameter. The method does not work for menu items with dynamic names (for example, “Group Panel Hide”, “Group Panel Show”).
// This code has no effect.
e.Menu.Remove(DevExpress.XtraGrid.Localization.GridStringId.MenuGroupPanelHide);
e.Menu.Remove(DevExpress.XtraGrid.Localization.GridStringId.MenuGroupPanelShow);
// This code works as expected.
e.Menu.Remove(DevExpress.XtraGrid.Localization.GridStringId.MenuColumnGroupBox);
#Summary Menu (DevExpress.XtraGrid.Menu.GridViewFooterMenu)
When handling the PopupMenuShowing and GridMenuItemClick events, you can identify this menu type using the e.MenuType event parameter, which is set to GridMenuType.Summary
The Tag properties of the items in this menu contain DevExpress.XtraGrid.Localization.GridStringId enumeration values.
Menu Item | Tag |
---|---|
Add New Summary (sub-menu) | DevExpress. |
Sum | DevExpress. |
Min | DevExpress. |
Max | DevExpress. |
Count | DevExpress. |
Average | DevExpress. |
None | DevExpress. |
Clear Summary Items | DevExpress. |
#Auto Filter Row Menu
When handling the PopupMenuShowing and GridMenuItemClick events, you can identify this menu type using the e.MenuType event parameter, which is set to GridMenuType.AutoFilter.
The Tag properties of the items in this menu contain DevExpress.XtraEditors.ColumnAutoFilterCondition enumeration values.
Menu Item | Tag |
---|---|
Clear Filter | null |
Equals | DevExpress. |
Does not equal | DevExpress. |
Contains | DevExpress. |
Does not contain | DevExpress. |
Is like | DevExpress. |
Is not like | DevExpress. |
Begins with | DevExpress. |
Ends with | DevExpress. |
Is greater than | DevExpress. |
Is greater than or equal to | DevExpress. |
Is less than | DevExpress. |
Is less than or equal to | DevExpress. |
#Example
The following code sample creates a menu item that fixes the column to the left. This item is added to the column header’s context menu next to the Hide This Column item:
void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
if (e.MenuType == GridMenuType.Column) {
DXMenuItem item = new DXMenuItem("Fix/Unfix This Column", (s, args) => {
GridColumn column = (s as DXMenuItem).Tag as GridColumn;
if (column.Fixed == FixedStyle.Left)
column.Fixed = FixedStyle.None;
else column.Fixed = FixedStyle.Left;
});
item.Tag = e.HitInfo.Column;
int index = e.Menu.Items.IndexOf(e.Menu.Find(GridStringId.MenuColumnRemoveColumn));
e.Menu.Items.Insert(index + 1, item);
}
}
Refer to the following help topic for more information: Modify Built-In Context Menus.
#Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Menu property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.