Back to Devexpress

PopupMenuShowingEventArgs Class

windowsforms-devexpress-dot-xtraverticalgrid-dot-events-07fc3162.md

latest4.5 KB
Original Source

PopupMenuShowingEventArgs Class

Provides data for the VGridControlBase.PopupMenuShowing event.

Namespace : DevExpress.XtraVerticalGrid.Events

Assembly : DevExpress.XtraVerticalGrid.v25.2.dll

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

Declaration

csharp
public class PopupMenuShowingEventArgs :
    BasePopupMenuShowingEventArgs
vb
Public Class PopupMenuShowingEventArgs
    Inherits BasePopupMenuShowingEventArgs

PopupMenuShowingEventArgs is the data class for the following events:

Remarks

The PopupMenuShowingEventArgs objects are automatically created, initialized and passed to the VGridControlBase.PopupMenuShowing event handlers.

Example

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

csharp
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);
}
vb
Imports DevExpress.Utils.Menu
Imports DevExpress.XtraVerticalGrid
Imports DevExpress.XtraVerticalGrid.Rows

Private Sub propertyGridControl1_PopupMenuShowing(ByVal sender As Object, ByVal e As DevExpress.XtraVerticalGrid.Events.PopupMenuShowingEventArgs) _
    Handles propertyGridControl1.PopupMenuShowing
    Dim pg As PropertyGridControl = TryCast(sender, PropertyGridControl)
    Dim hi As VGridHitInfo = pg.CalcHitInfo(pg.PointToClient(Cursor.Position))
    If hi.Row Is Nothing OrElse hi.Row.Properties.FieldName <> "Enabled" Then
        Return
    End If
    ToggleMenuItem.Tag = hi.Row
    e.Menu.Items.Add(ToggleMenuItem)

End Sub
Private toggleMenuItem1 As DXMenuItem
Protected ReadOnly Property ToggleMenuItem() As DXMenuItem
    Get
        If toggleMenuItem1 Is Nothing Then
            Dim item As New DXMenuItem("Toggle")
            AddHandler item.Click, AddressOf item_Click
            toggleMenuItem1 = item
        End If
        Return toggleMenuItem1
    End Get
End Property
Private Sub item_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim row As BaseRow = TryCast((TryCast(sender, DXMenuItem)).Tag, BaseRow)
    Dim cellValue As Boolean = DirectCast(row.Grid.GetCellValue(row, 0), Boolean)
    row.Grid.SetCellValue(row, 0, Not cellValue)
End Sub

Inheritance

Object EventArgs BasePopupMenuShowingEventArgs PopupMenuShowingEventArgs

See Also

PopupMenuShowingEventArgs Members

DevExpress.XtraVerticalGrid.Events Namespace