TreeListNode.HasChildren Property

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

Namespace: DevExpress.XtraTreeList.Nodes

Assembly: DevExpress.XtraTreeList.v21.2.dll


public virtual bool HasChildren { get; set; }

Property Value

Type Description

true if a node has children; otherwise, false.


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.


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