Back to Devexpress

Control the Availability of Standard Context Menus to Users

windowsforms-5687-controls-and-libraries-tree-list-feature-center-context-menus-control-the-availability-of-the-standard-context-menus-to-end-users.md

latest3.8 KB
Original Source

Control the Availability of Standard Context Menus to Users

  • Mar 01, 2024
  • 2 minutes to read

There are two ways to control the availability of the standard context menus to end-users: via corresponding options and by handling an event.

Control the Display of Menus via Options

Menu options that control the availability of the standard context menus can be accessed via the TreeList.OptionsMenu property. These options allow you to disable or enable the column header and footer menus. Note that the Tree List elements for which menus are activated must be visible to allow the menus to be invoked. The visibility of these elements is controlled by the view options that can be accessed via the TreeList.OptionsView property.

The table below lists the types of menu and their visibility conditions.

Menu TypeVisibility Condition
Column Header Panel MenuThe TreeListOptionsMenu.EnableColumnMenu property must be set to true. The TreeListOptionsView.ShowColumns property must be set to true to display column headers.
Row Footer MenuThe TreeListOptionsMenu.EnableFooterMenu property must be set to true. The TreeListOptionsView.ShowRowFooterSummary property must be set to true to display row footers.
Summary Footer MenuThe TreeListOptionsMenu.EnableFooterMenu property must be set to true. The TreeListOptionsView.ShowSummaryFooter property must be set to true to display the summary footer.
Node MenuThe TreeListOptionsMenu.EnableNodeMenu property must be set to true.

For instance, you can write the following code to enable the column header menu and disable the footer menus.

csharp
treeList1.OptionsMenu.EnableColumnMenu = true;
treeList1.OptionsMenu.EnableFooterMenu = false;
vb
TreeList1.OptionsMenu.EnableColumnMenu = True
TreeList1.OptionsMenu.EnableFooterMenu = False

Control the Display of Menus via Event

The TreeList.PopupMenuShowing event fires each time an end-user attempts to invoke any standard context menu. The event’s parameters allow you to identify the type of menu, customize the menu or prevent it from being invoked. The following sample code handles the TreeList.PopupMenuShowing event to prohibit the menu for the Department column from being invoked.

csharp
void TreeList1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    if (e.MenuType == TreeListMenuType.Column && e.HitInfo.Column.FieldName == nameof(SalesData.Department))
        e.Allow = false;
}
vb
Private Sub TreeList1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
    If e.MenuType = TreeListMenuType.Column AndAlso e.HitInfo.Column.FieldName = NameOf(SalesData.Department) Then e.Allow = False
End Sub