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

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.v20.1.dll

NuGet Package: 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
True

Corresponds to a Boolean value of true.

False

Corresponds to a Boolean value of false.

Default

The value is determined by the current object’s parent object setting (e.g., a control setting).

Property Paths

You can access this nested property as listed below:

Library Object Type Path to ShowAddNodeItems
WinForms Controls GanttControl
.OptionsMenu .ShowAddNodeItems
ResourcesTree
.OptionsMenu .ShowAddNodeItems
TreeList
.OptionsMenu .ShowAddNodeItems
Reporting XRDesignFieldList
.OptionsMenu .ShowAddNodeItems
XRDesignReportExplorer
.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.

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