windowsforms-devexpress-dot-xtratreelist-dot-nodes-dot-treelistnode-1fd5b722.md
Gets or sets a value indicating whether a node has children.
Namespace : DevExpress.XtraTreeList.Nodes
Assembly : DevExpress.XtraTreeList.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList
[Browsable(false)]
[DXCategory("Behavior")]
public virtual bool HasChildren { get; set; }
<Browsable(False)>
<DXCategory("Behavior")>
Public Overridable Property HasChildren As Boolean
| Type | Description |
|---|---|
| Boolean |
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;
}
Imports DevExpress.XtraTreeList
Private Sub TreeList1_BeforeDragNode(ByVal sender As Object, _
ByVal e As BeforeDragNodeEventArgs) Handles TreeList1.BeforeDragNode
If e.Node.HasChildren Then e.CanDrag = False
End Sub
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.
node.StateImageIndex = 0;
node.HasChildren = HasFiles(s);
if (node.HasChildren)
winforms-treelist-create-file-manager-drag-drop-files-folders/CS/FileList/FileListHelper.cs#L101
node.StateImageIndex = 0;
node.HasChildren = HasFiles(s);
if (node.HasChildren)
winforms-treelist-implement-group-level-style-feature/CS/Q220534/Form1.cs#L39
if (currentNode == null) return;
if (currentNode.HasChildren)
rects.Add(currentNode.Level, new Rectangle(bounds.Right - viewInfo.RC.LevelWidth, bounds.Y, viewInfo.RC.LevelWidth, bounds.Height));
winforms-treelist-save-restore-expanded-state-of-nodes/CS/TreeListViewState.cs#L89
public override void Execute(TreeListNode node) {
if(node.HasChildren && node.Expanded)
al.Add(node.GetValue(node.TreeList.KeyFieldName));
node.StateImageIndex = 0
node.HasChildren = HasFiles(s)
If node.HasChildren Then node.Tag = True
winforms-treelist-create-file-manager-drag-drop-files-folders/VB/FileList/FileListHelper.vb#L83
node.StateImageIndex = 0
node.HasChildren = HasFiles(s)
If node.HasChildren Then node.Tag = True
winforms-treelist-implement-group-level-style-feature/VB/Q220534/Form1.vb#L38
End If
If currentNode.HasChildren Then
rects.Add(currentNode.Level, New Rectangle(bounds.Right - viewInfo.RC.LevelWidth, bounds.Y, viewInfo.RC.LevelWidth, bounds.Height))
winforms-treelist-save-restore-expanded-state-of-nodes/VB/TreeListViewState.vb#L97
Public Overrides Sub Execute(ByVal node As TreeListNode)
If node.HasChildren AndAlso node.Expanded Then
al.Add(node.GetValue(node.TreeList.KeyFieldName))
See Also