GridView.ShowGridMenu Event

Obsolete. Enables you to customize or prohibit grid context menus.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

[DXCategory("Behavior")]
[Browsable(false)]
[Obsolete("You should use the 'PopupMenuShowing' instead", false)]
public event GridMenuEventHandler ShowGridMenu
<DXCategory("Behavior")>
<Browsable(False)>
<Obsolete("You should use the 'PopupMenuShowing' instead", False)>
Public Event ShowGridMenu As GridMenuEventHandler

Event Data

The ShowGridMenu event's data class is GridMenuEventArgs. The following properties provide information specific to this event:

Property Description
Allow Gets or sets whether to enable the Grid's popup menu. Inherited from PopupMenuShowingEventArgs.
HitInfo Gets an object that identifies a clicked element. Inherited from PopupMenuShowingEventArgs.
Menu Gets or sets the popup menu that is about to be displayed. Inherited from PopupMenuShowingEventArgs.
MenuType Gets the type of the Grid View's menu to be invoked. Inherited from PopupMenuShowingEventArgs.
Point Gets the position where the menu is to be invoked. Inherited from PopupMenuShowingEventArgs.

Remarks

The ShowGridMenu event is obsolete. Use the GridView.PopupMenuShowing event instead.

Examples

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 command that locks a clicked column's position.

GridView_ShowGridMenu

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(OnCanMoveItemClick));
    item.Tag = new MenuColumnInfo(column);
    return item;
}

// Menu item click handler.
void OnCanMoveItemClick(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;
}

class MenuColumnInfo {
    public MenuColumnInfo(GridColumn column) {
        this.Column = column;               
    }
    public GridColumn Column;
}
See Also