All docs
V20.1
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Empty Area Context Menu

  • 2 minutes to read

The control can show a context menu when a user right-clicks the area below nodes. The default context menu for this area does not contain commands.

Populate the Menu

The PopupMenuShowing event is raised before the control shows a context menu. Handle this event to populate the menu with commands. Use the HitInfo event argument to get the clicked visual element. If this property is set to Empty, a user right-clicked the empty area.

The code below adds the Full Collapse and Full Expand commands to the empty area context menu.

using DevExpress.Utils.Menu;
using DevExpress.Utils.Svg;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Localization;

treeList1.PopupMenuShowing += OnPopupMenuShowing;

void OnPopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    TreeList treeList = sender as TreeList;
    if(e.HitInfo.HitInfoType == HitInfoType.Empty) {
        string expandAllCaption = TreeListLocalizer.Active.GetLocalizedString(TreeListStringId.MenuNodeExpandAll);
        DXMenuItem expandAll = new DXMenuItem(expandAllCaption, (ss, ee) => treeList.ExpandAll());
        expandAll.ImageOptions.SvgImage = CommonSvgImages.Get(CommonSvgImages.Column.ExpandAll);
        e.Menu.Items.Add(expandAll);
        string collapseAllCaption = TreeListLocalizer.Active.GetLocalizedString(TreeListStringId.MenuNodeCollapseAll);
        DXMenuItem collapseAll = new DXMenuItem(collapseAllCaption, (ss, ee) => treeList.CollapseAll());
        collapseAll.ImageOptions.SvgImage = CommonSvgImages.Get(CommonSvgImages.Column.CollapseAll);
        e.Menu.Items.Add(collapseAll);
        e.Allow = true;
    }
}