GridView.PopupMenuShowing Event
Enables you to customize or prohibit grid context menus.
Namespace: DevExpress.XtraGrid.Views.Grid
Assembly: DevExpress.XtraGrid.v17.2.dll
Declaration
Event Data
The PopupMenuShowing event's data class is PopupMenuShowingEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Allow | Gets or sets whether to enable the Grid’s popup menu. |
HitInfo | Gets an object that identifies a clicked element. |
Menu | Gets or sets the Grid’s popup menu that will be shown. |
MenuType | Gets the type of the Grid View’s menu to be invoked. |
Point | Gets the position where the menu is to be invoked. |
Remarks
Grid Views provide several context menus to end-users. These menu’s availability is controlled by the View’s GridView.OptionsMenu property. The property provides access to an object that contains a set of Boolean properties. Each property specifies whether particular types of menus are available.
If the GridView.OptionsMenu property allows you to invoke a menu, the PopupMenuShowing event fires each time a user attempts to invoke a context menu. This event’s parameters enable you to identify which menu is about to be displayed, customize the menu or prohibit it from being invoked.
Example
The following sample code handles the GridView.PopupMenuShowing event to customize the column header context menu before it is displayed. The code clears default menu items and adds a new one which determines whether the column header can be moved within the column header panel.
using DevExpress.XtraGrid.Menu;
using DevExpress.Utils.Menu;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
// ...
private void bandedGridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
if(e.MenuType == GridMenuType.Column) {
GridViewColumnMenu menu = e.Menu as GridViewColumnMenu;
menu.Items.Clear();
if(menu.Column != null) {
menu.Items.Add(CreateCheckItem("Lock this column", menu.Column, null));
}
}
}
// Creates a menu item.
DXMenuCheckItem CreateCheckItem(string caption, GridColumn column, Image image) {
DXMenuCheckItem item = new DXMenuCheckItem(caption,
!column.OptionsColumn.AllowMove, image, new EventHandler(OnCanMovedItemClick));
item.Tag = new MenuColumnInfo(column);
return item;
}
// Menu item click handler.
void OnCanMovedItemClick(object sender, EventArgs e) {
DXMenuCheckItem item = sender as DXMenuCheckItem;
MenuColumnInfo info = item.Tag as MenuColumnInfo;
if(info == null) return;
info.Column.OptionsColumn.AllowMove = !item.Checked;
}
// The class that stores menu specific information.
class MenuColumnInfo {
public MenuColumnInfo(GridColumn column) {
this.Column = column;
}
public GridColumn Column;
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the PopupMenuShowing event.
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.