Skip to main content

TreeListNode.HasChildren Property

Gets or sets a value indicating whether a node has children.

Namespace: DevExpress.XtraTreeList.Nodes

Assembly: DevExpress.XtraTreeList.v24.2.dll

Declaration

[Browsable(false)]
[DXCategory("Behavior")]
public virtual bool HasChildren { get; set; }

Property Value

Type Description
Boolean

true if a node has children; otherwise, false.

Remarks

When the HasChildren and TreeListOptionsView.ShowButtons properties are set to true, the ‘+’ or ‘-‘ button appears to the left of the node name. The ‘+’ button is displayed when a node is collapsed. To expand a node just click it. The TreeList.BeforeExpand and TreeList.AfterExpand events are generated in this instance.

The ‘-‘ button is displayed when a node has children and is expanded. When a user clicks the ‘-‘ button, the TreeList.BeforeCollapse event is generated, the node collapses and the TreeList.AfterCollapse event is raised.

You can prevent expanding or collapsing a node by setting the BeforeExpandEventArgs.CanExpand and BeforeCollapseEventArgs.CanCollapse properties in the TreeList.BeforeExpand and TreeList.BeforeCollapse event handlers to false.

The ‘+’ button indicates visually that the current node contains children, but it is not necessarily the case that the TreeListNode.Nodes property contains them. For instance, this can be used to display child nodes dynamically. To do so, set the HasChildren property to true and implement adding child nodes in a TreeList.BeforeExpand event handler. Thus, child nodes will be added only by user demand.

Example

The following sample code prohibits parent node dragging. The TreeList.BeforeDragNode event is handled for this purpose. The TreeListNode.HasChildren property is used to identify whether the currently processed node has child nodes.

using DevExpress.XtraTreeList;

private void treeList1_BeforeDragNode(object sender, BeforeDragNodeEventArgs e) {
   if (e.Node.HasChildren) e.CanDrag = false;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the HasChildren 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