Skip to main content

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.v23.2.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.TreeList

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:

Object Type Path to EnableNodeMenu
TreeList
.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.

image

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, use the TreeList.OptionsMenu.ShowExpandCollapseItems option.

If the control displays the New Item Row, the context menu also contains the following commands:

  • Add Node — creates a new node at the same level as the focused node.
  • Add Child Node — creates a new child node for the focused node.

To hide/show these commands regardless of whether the New Item Row is displayed, use the TreeList.OptionsMenu.ShowAddNodeItems option.

Localize the Menu

The TreeListLocalizer allows you to localize the command captions. Use the following fields to identify a command:

  • MenuNodeCollapse — the Collapse command.
  • MenuNodeExpand — the Expand command.
  • MenuNodeExpandAll — the Full Expand command.
  • MenuNodeCollapseAll — the Full Collapse command.
  • MenuNodeAddNode — the Add Node command.
  • MenuNodeAddChildNode — the Add Child Node command.
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.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EnableNodeMenu property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also