Skip to main content

GridControl.ColumnMenu Property

Gets or sets the context menu that is invoked when the end-user right-clicks a column header.

Namespace: DevExpress.UI.Xaml.Grid

Assembly: DevExpress.UI.Xaml.Grid.v21.2.dll

NuGet Package: DevExpress.Uwp.Controls

Declaration

public object ColumnMenu { get; set; }

Property Value

Type Description
Object

The UI element invoked when the end-user right-clicks a column header.

Remarks

The ColumnMenu property allows you to define a custom Context Menu for GridControl column headers. You can use either the standard MenuFlyout control in this property, or our ContextToolbarControl or ToolbarControl.

When you define a menu control in ColumnMenu, this control’s DataContext is set to an object of the GridColumnContextMenuInfo class. This class provides information about your GridControl, a view model stored in its DataContext, a target column, etc. You can use this information to process different actions at your view model level.

A menu defined in this property will be used instead of the default column context menu. The below snippet illustrates how to define ContextToolbarControl in this property:

xmlns:dxg="using:DevExpress.UI.Xaml.Grid"
xmlns:dxr="using:DevExpress.UI.Xaml.Ribbon"

<dxg:GridControl ...>
    <dxg:GridControl.ColumnMenu>
        <dxr:ContextToolbarControl Orientation="Vertical">
            <dxr:ContextToolbarGroup>
                <dxr:ContextToolbarButton Content="Clear Grouping"
                                    Command="{Binding Commands.ClearGrouping}"/>
                <dxr:ContextToolbarButton Content="Clear Filter"
                                    Command="{Binding Commands.ClearFilter}"/>
            </dxr:ContextToolbarGroup>
        </dxr:ContextToolbarControl>
    </dxg:GridControl.ColumnMenu>
</dxg:GridControl>

If you only want to add custom items to the default column context menu, you can do this in the GridControl.ContextMenuOpening event handler:

private void GridControl_ContextMenuOpening(object sender, DevExpress.UI.Xaml.ContextMenuOpeningEventArgs e)
{
    var menuInfo = e.Info as GridColumnContextMenuInfo;
    if(menuInfo != null)
    {
        var toolbar = menuInfo.MenuContent as ContextToolbarControl;
        toolbar.Group.Items.Add(new ContextToolbarButton() { Content = "Clear Filtering", Command = menuInfo.Commands.ClearFilter });
        toolbar.Group.Items.Add(new ContextToolbarButton() { Content = "Clear Grouping", Command = menuInfo.Commands.ClearGrouping });
    }
}
See Also