Control the Availability of the Standard Context Menus to End-Users

  • 2 minutes to read

There are two ways to control the availability of the stadard 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 Type Visibility Condition
Column Header Panel Menu The TreeListOptionsMenu.EnableColumnMenu property must be set to true. The TreeListOptionsView.ShowColumns property must be set to true to display column headers.
Row Footer Menu The TreeListOptionsMenu.EnableFooterMenu property must be set to true. The TreeListOptionsView.ShowRowFooterSummary property must be set to true to display row footers.
Summary Footer Menu The TreeListOptionsMenu.EnableFooterMenu property must be set to true. The TreeListOptionsView.ShowSummaryFooter property must be set to true to display the summary footer.

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

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.

using DevExpress.XtraTreeList;
//...
private void treeList1_ShowTreeListMenu(object sender, DevExpress.XtraTreeList.TreeListMenuEventArgs e) {
   TreeListHitInfo hitInfo = (sender as TreeList).CalcHitInfo(e.Point);
   if(hitInfo.HitInfoType == HitInfoType.Column && hitInfo.Column.Caption == "Department")
      e.Allow = false;
}