Skip to main content

VGridControlBase.ShowMenu Event

OBSOLETE

Use 'PopupMenuShowing' instead

Allows context menus for rows to be customized.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v23.2.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid

Declaration

[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use 'PopupMenuShowing' instead", false)]
public event VGridControlMenuEventHandler ShowMenu

Event Data

The ShowMenu event's data class is DevExpress.XtraVerticalGrid.Events.VGridControlMenuEventArgs.

Remarks

The ShowMenu event fires when right-clicking within a row, if the Grid.OptionsMenu.EnableContextMenu property is set to true (by default, it’s set to false).

By default, context menus for the VGridControl are empty, and they are not displayed. To create and display a context menu for this control, set the Grid.OptionsMenu.EnableContextMenu property to true, and then populate the menu via the ShowMenu event.

To enable the context menus for a PropertyGridControl, set the Grid.OptionsMenu.EnableContextMenu property to true. The context menu for this control contains the Reset command, allowing a property to be reset to the default value. You can handle the ShowMenu event to customize the context menu (add new items or remove existing items).

To paint context menus according to the current look and feel, use the control’s EditorContainer.MenuManager property.

Example

This example shows how to add a command that toggles the Enabled property to a context menu.

using DevExpress.Utils.Menu;
using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Rows;

propertyGridControl1.PopupMenuShowing += propertyGridControl1_PopupMenuShowing;
private void propertyGridControl1_PopupMenuShowing(object sender, DevExpress.XtraVerticalGrid.Events.PopupMenuShowingEventArgs e) {
    PropertyGridControl pg = sender as PropertyGridControl;
    VGridHitInfo hi = pg.CalcHitInfo(pg.PointToClient(Cursor.Position));
    if (hi.Row == null || hi.Row.Properties.FieldName != "Enabled") return;
    ToggleMenuItem.Tag = hi.Row;
    e.Menu.Items.Add(ToggleMenuItem);

}
DXMenuItem toggleMenuItem;
protected DXMenuItem ToggleMenuItem {
    get {
        if (toggleMenuItem == null) {
            DXMenuItem item = new DXMenuItem("Toggle");
            item.Click += item_Click;
            toggleMenuItem = item;
        }
        return toggleMenuItem;
    }
}
void item_Click(object sender, EventArgs e) {
    BaseRow row = (sender as DXMenuItem).Tag as BaseRow;
    bool cellValue = (bool)row.Grid.GetCellValue(row, 0);
    row.Grid.SetCellValue(row, 0, !cellValue);
}
See Also