Back to Devexpress

PopupMenuShowingEventArgs Class

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-54a596da.md

latest4.1 KB
Original Source

PopupMenuShowingEventArgs Class

Contains data for the GridView.PopupMenuShowing event.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

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

PopupMenuShowingEventArgs is the data class for the following events:

Example

The following code sample invokes a custom context menu when a user right-clicks a column header:

  1. Add a BarManager to the form and create a custom PopupMenu.

  2. Handle the GridView.PopupMenuShowing event and call the e.ShowCustomMenu method to display your custom menu instead of the default header menu.

csharp
void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    if (e.MenuType == GridMenuType.Column) {
        popupMenu_Column.Tag = e.HitInfo;
        popupMenu_Column.MenuCaption = $"{e.HitInfo.Column}";

        e.ShowCustomMenu(popupMenu_Column);
    }
}

GridHitInfo GetHitInfo(BarItemLink link) {
    PopupMenu menu = link.LinkedObject as PopupMenu;
    return menu.Tag as GridHitInfo;
}
void barButtonItem_Filter_ItemClick(object sender, ItemClickEventArgs e) {
    GridHitInfo info = GetHitInfo(e.Link);
    info.View.ShowFilterEditor(info.Column);
}

void barButtonItem_ColumnChooser_ItemClick(object sender, ItemClickEventArgs e) {
    GridHitInfo info = GetHitInfo(e.Link);
    info.View.ShowCustomization();
}
vb
Private Sub gridView1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    If e.MenuType = GridMenuType.Column Then
        popupMenu_Column.Tag = e.HitInfo
        popupMenu_Column.MenuCaption = $"{e.HitInfo.Column}"

        e.ShowCustomMenu(popupMenu_Column)
    End If
End Sub

Private Function GetHitInfo(ByVal link As BarItemLink) As GridHitInfo
    Dim menu As PopupMenu = TryCast(link.LinkedObject, PopupMenu)
    Return TryCast(menu.Tag, GridHitInfo)
End Function

Private Sub barButtonItem_Filter_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim info As GridHitInfo = GetHitInfo(e.Link)
    info.View.ShowFilterEditor(info.Column)
End Sub

Private Sub barButtonItem_ColumnChooser_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim info As GridHitInfo = GetHitInfo(e.Link)
    info.View.ShowCustomization()
End Sub

Inheritance

Object EventArgs BasePopupMenuShowingEventArgs PopupMenuShowingEventArgs GridMenuEventArgs

See Also

PopupMenuShowingEventArgs Members

DevExpress.XtraGrid.Views.Grid Namespace