Skip to main content
All docs
V25.1
  • Node Context Menu

    • 2 minutes to read

    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.

    Use the TreeList.OptionsMenu.ShowExpandCollapseItems property to hide these commands.

    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.

    Use the TreeList.OptionsMenu.ShowAddNodeItems property to hide/show these items regardless of the New Item Row visibility.

    Refer to the following help topic for more information on how to customize this menu: Context Menus.

    View Example: Customize Node Context Menu

    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);
            }
        }
    }
    
    See Also