Skip to main content
A newer version of this page is available. .

TreeListOptionsMenu.EnableNodeMenu Property

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

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v19.2.dll

Declaration

[DefaultValue(true)]
[XtraSerializableProperty]
public virtual bool EnableNodeMenu { get; set; }

Property Value

Type Default Description
Boolean **true**

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

Property Paths

You can access this nested property as listed below:

Library Object Type Path to EnableNodeMenu
WinForms Controls GanttControl
.OptionsMenu.EnableNodeMenu
ResourcesTree
.OptionsMenu.EnableNodeMenu
TreeList
.OptionsMenu.EnableNodeMenu
Reporting XRDesignFieldList
.OptionsMenu.EnableNodeMenu
XRDesignReportExplorer
.OptionsMenu.EnableNodeMenu

Remarks

If the TreeList.OptionsMenu.EnableNodeMenu option is enabled, the tree list shows a context menu when a user right-clicks a node.

Predefined commands

The context menu contains the following predefined commands:

  • Collapse (Expand) — collapses (expands) the clicked node. This command is only shown when the node has children.
  • Full Collapse — collapses all nodes.
  • Full Expand — expands all nodes.

To hide these commands, disable the TreeList.OptionsMenu.ShowExpandCollapseItems option.

Localize the menu

The TreeListLocalizer allows you to localize the command captions. Use the MenuNodeCollapse, MenuNodeExpand, MenuNodeExpandAll and MenuNodeCollapseAll fields to identify the commands.

using DevExpress.XtraTreeList.Localization;

TreeListLocalizer.Active = new NodeContextMenuLocalizer();

public class NodeContextMenuLocalizer : TreeListLocalizer {
    public override string Language { get { return "English"; } }
    public override string GetLocalizedString(TreeListStringId id) {
        switch (id) {
            case TreeListStringId.MenuNodeCollapse: return "Collapse this node";
            case TreeListStringId.MenuNodeExpand: return "Expand this node";
            case TreeListStringId.MenuNodeExpandAll: return "Expand all nodes";
            case TreeListStringId.MenuNodeCollapseAll: return "Collapse all nodes";
            default: return base.GetLocalizedString(id);
        }
    }
}

Populate the menu

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

using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Menu;

treeList1.PopupMenuShowing += OnPopupMenuShowing;

void OnPopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    if (e.Menu is DevExpress.XtraTreeList.Menu.TreeListNodeMenu) {
        AddItem(e.Menu, NodeMenuItemID.Indent, treeList1.CanIndentNodes(treeList1.Selection));
        AddItem(e.Menu, NodeMenuItemID.Outdent, treeList1.CanOutdentNodes(treeList1.Selection));
        e.Allow = true;
    }
}

Note

Run the XtraTreeList demo and click Open Solution to see the complete example.

See Also