Back to Devexpress

Disable and Remove Items in Standard Menus

windowsforms-5699-controls-and-libraries-tree-list-feature-center-context-menus-disable-and-remove-particular-items-in-the-standard-menus.md

latest2.4 KB
Original Source

Disable and Remove Items in Standard Menus

  • Mar 01, 2024
  • 2 minutes to read

Handle the TreeList.PopupMenuShowing event and use the e.Menu property to access the invoked menu. You can use e.Menu.Hide and e.Menu.Remove methods to hide and remove menu items or the e.Menu.Find method to obtain a specific menu item and modify it.

Example

The following sample code handles the TreeList.PopupMenuShowing event to execute the following actions:

  • Disable Min and Max items in the summary footer context menu for the “Department” column.
  • Remove the Column Chooser item from the column header context menu.

csharp
void TreeList1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    // Disable Min and Max items in the summary footer menu for the "Department" column:
    if (e.MenuType == TreeListMenuType.Summary && e.HitInfo.Column.FieldName == nameof(SalesData.Department)) {
        e.Menu.Find(TreeListStringId.MenuFooterMax).Enabled = false;
        e.Menu.Find(TreeListStringId.MenuFooterMin).Enabled = false;
    }
    // Remove the "Column Chooser" item from the column header menu:
    if (e.MenuType == TreeListMenuType.Column) {
        e.Menu.Remove(TreeListStringId.MenuColumnColumnCustomization);
        e.Menu.Remove(TreeListStringId.MenuColumnBandCustomization);
    }
}
vb
Private Sub TreeList1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    ' Disable Min and Max items in the summary footer menu for the "Department" column:
    If e.MenuType = TreeListMenuType.Summary AndAlso e.HitInfo.Column.FieldName = NameOf(SalesData.Department) Then
        e.Menu.Find(TreeListStringId.MenuFooterMax).Enabled = False
        e.Menu.Find(TreeListStringId.MenuFooterMin).Enabled = False
    End If
    ' Remove the "Column Chooser" item from the column header menu:
    If e.MenuType = TreeListMenuType.Column Then
        e.Menu.Remove(TreeListStringId.MenuColumnColumnCustomization)
        e.Menu.Remove(TreeListStringId.MenuColumnBandCustomization)
    End If
End Sub