Back to Devexpress

GridOptionsMenu.EnableGroupRowMenu Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridoptionsmenu-2c55db53.md

latest5.8 KB
Original Source

GridOptionsMenu.EnableGroupRowMenu Property

Gets or sets whether users can invoke a context menu with a right-click on a group row.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
[DefaultValue(false)]
[XtraSerializableProperty]
public virtual bool EnableGroupRowMenu { get; set; }
vb
<DefaultValue(False)>
<XtraSerializableProperty>
Public Overridable Property EnableGroupRowMenu As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

true if users can invoke a context menu with a right-click on a group row; otherwise, false.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to EnableGroupRowMenu
GridView

.OptionsMenu .EnableGroupRowMenu

|

Remarks

If the GridView.OptionsMenu.EnableGroupRowMenu option is enabled, the grid view shows a context menu when a user right-clicks a group.

Predefined commands

The context menu contains the following predefined commands:

  • Collapse ( Expand ) — collapses (expands) the clicked group.
  • Full Collapse — collapses all groups.
  • Full Expand — expands all groups.

Localize the menu

The GridLocalizer allows you to localize the command captions. Use the MenuGroupRowCollapse , MenuGroupRowExpand , MenuGroupPanelFullExpand and MenuGroupPanelFullCollapse fields to identify the commands.

csharp
using DevExpress.XtraGrid.Localization;

GridLocalizer.Active = new GroupRowContextMenuLocalizer();

public class GroupRowContextMenuLocalizer : GridLocalizer {
    public override string Language { get { return "English"; } }
    public override string GetLocalizedString(GridStringId id) {
        switch (id) {
            case GridStringId.MenuGroupRowCollapse: return "Collapse this group";
            case GridStringId.MenuGroupRowExpand: return "Expand this groups";
            case GridStringId.MenuGroupPanelFullExpand: return "Expand all groups";
            case GridStringId.MenuGroupPanelFullCollapse: return "Collapse all nodes";
            default: return base.GetLocalizedString(id);
        }
    }
}
vb
Imports DevExpress.XtraGrid.Localization

GridLocalizer.Active = New GroupRowContextMenuLocalizer()

Public Class GroupRowContextMenuLocalizer
    Inherits GridLocalizer

    Public Overrides ReadOnly Property Language() As String
        Get
            Return "English"
        End Get
    End Property
    Public Overrides Function GetLocalizedString(ByVal id As GridStringId) As String
        Select Case id
            Case GridStringId.MenuGroupRowCollapse
                Return "Collapse this group"
            Case GridStringId.MenuGroupRowExpand
                Return "Expand this groups"
            Case GridStringId.MenuGroupPanelFullExpand
                Return "Expand all groups"
            Case GridStringId.MenuGroupPanelFullCollapse
                Return "Collapse all nodes"
            Case Else
                Return MyBase.GetLocalizedString(id)
        End Select
    End Function
End Class

Populate the menu

You can handle the GridView.PopupMenuShowing event to populate the menu with custom items.

csharp
using DevExpress.XtraGrid.Localization;

gridView1.PopupMenuShowing += GridView1_PopupMenuShowing;

private void GridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e) {
    if (e.Menu is DevExpress.XtraGrid.Menu.GridViewGroupRowMenu) {
        DevExpress.Utils.Menu.DXMenuItem item = new DevExpress.Utils.Menu.DXMenuItem();
        item.Caption = "Item";
        item.Click += (ss, ee) => { MessageBox.Show("Item clicked"); };
        e.Menu.Items.Add(item);
        e.Allow = true;
    }
}
vb
Imports DevExpress.XtraGrid.Localization

AddHandler gridView1.PopupMenuShowing, AddressOf GridView1_PopupMenuShowing

Private Sub GridView1_PopupMenuShowing(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs)
    If TypeOf e.Menu Is DevExpress.XtraGrid.Menu.GridViewGroupRowMenu Then
        Dim item As New DevExpress.Utils.Menu.DXMenuItem()
        item.Caption = "Item"
        AddHandler item.Click, Sub(ss, ee)
            MessageBox.Show("Item clicked")
        End Sub
        e.Menu.Items.Add(item)
        e.Allow = True
    End If
End Sub

See Also

GridOptionsMenu Class

GridOptionsMenu Members

DevExpress.XtraGrid.Views.Grid Namespace