Back to Devexpress

Node Context Menu

windowsforms-401606-controls-and-libraries-tree-list-visual-elements-node-context-menu.md

latest4.0 KB
Original Source

Node Context Menu

  • Mar 01, 2024
  • 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.

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.

  • C#

  • VB.NET

csharp
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);
        }
    }
}
vb
Imports DevExpress.XtraTreeList.Localization

TreeListLocalizer.Active = New NodeContextMenuLocalizer()

Public Class NodeContextMenuLocalizer
    Inherits TreeListLocalizer

    Public Overrides ReadOnly Property Language() As String
        Get
            Return "English"
        End Get
    End Property
    Public Overrides Function GetLocalizedString(ByVal id As TreeListStringId) As String
        Select Case 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"
            Case Else
                Return MyBase.GetLocalizedString(id)
        End Select
    End Function
End Class

See Also

Context Menus