Skip to main content

TreeListOptionsMenu.ShowAddNodeItems Property

Gets or sets whether the node context menu contains commands that allow users to add new nodes.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v23.2.dll

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

Declaration

[DefaultValue(DefaultBoolean.Default)]
[XtraSerializableProperty]
public virtual DefaultBoolean ShowAddNodeItems { get; set; }

Property Value

Type Default Description
DefaultBoolean Default

True, if the context menu displays the Add Node and Add Child Node commands; False, if not; Default, if the visibility depends on the New Item Row visibility.

Available values:

Name Description Return Value
True

The value is true.

0

False

The value is false.

1

Default

The value is specified by a global option or a higher-level object.

2

Property Paths

You can access this nested property as listed below:

Object Type Path to ShowAddNodeItems
TreeList
.OptionsMenu .ShowAddNodeItems

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.

See Also