Skip to main content
A newer version of this page is available. .

VGridControlBase.PopupMenuShowing Event

Allows context menus for rows to be customized.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v18.1.dll

Declaration

public event PopupMenuShowingEventHandler PopupMenuShowing

Event Data

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

Property Description
Menu Gets or sets the control’s popup menu that will be shown.
Row Gets the row where the popup menu will be displayed.

Remarks

The PopupMenuShowing event fires when right-clicking within a row, if the Grid.OptionsMenu.EnableContextMenu (VGridOptionsMenu.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 PopupMenuShowing 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 PopupMenuShowing 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

The following code shows how to customize a context menu for a PropertyGridControl via its VGridControlBase.PopupMenuShowing event. In the code below, an Invert menu item is added to the context menu shown for an Enabled row. When an end-user selects this item, the Enabled row’s value is toggled.

Note

Context menus in a PropertyGridControl are enabled if the OptionsMenu.EnableContextMenu property is set to true.

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

private void propertyGridControl1_PopupMenuShowing(object sender, 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;            
    // Create a new menu item
    DXMenuItem item = new DXMenuItem("Invert");
    item.Click += new EventHandler(item_Click);
    item.Tag = hi.Row;
    e.Menu.Items.Add(item);
}
// The Invert item's Click event handler
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