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

GridViewBase.GridMenu Property

Gets the context menu currently being displayed within a View.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v18.2.dll

Declaration

public GridPopupMenu GridMenu { get; }

Property Value

Type Description
GridPopupMenu

A GridPopupMenu object that represents the context menu displayed within a View. null (Nothing in Visual Basic) if no menu is currently displayed within a View.

Remarks

To learn more, see Context Menus.

Example

The following example demonstrates how to modify a column header in a grid’s Table View. In this sample, we illustrate how to add a button with an icon to a column header’s customization area.

For this, it is necessary to define a DataTemplate, which represents a button, and assign it to the DataViewBase.ColumnHeaderCustomizationAreaTemplate property. This template specifies a button and some of its properties. For example, it invokes the standard context menu on clicking this button (but disables invoking this menu when either the column header or the custom button within it are clicked).

private void TableView_ShowGridMenu(object sender, GridMenuEventArgs e) {
    // Check whether this event was raised for a column's context menu.
    // If not - exit and leave the menu shown.
    if (e.MenuType != GridMenuType.Column) return;

    // Check whether this event was raised for a custom button.
    // If not - exit and hide the menu.
    if ((e.TargetElement as Control).Tag == null) {
        e.Handled = true;
        return;
    }
}

private void Button_Click(object sender, RoutedEventArgs e) {
    // Show the context menu when a custom button is clicked.
    view.GridMenu.ShowPopup(sender as Button);
}

private void Button_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e) {
    // Don't show the context menu when a custom button is right-clicked.
    e.Handled = true;
}
See Also