Back to Devexpress

TreeListNode.Nodes Property

windowsforms-devexpress-dot-xtratreelist-dot-nodes-dot-treelistnode-02f1db16.md

latest7.3 KB
Original Source

TreeListNode.Nodes Property

Gets the collection of the node’s children.

Namespace : DevExpress.XtraTreeList.Nodes

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

csharp
[Browsable(false)]
public virtual TreeListNodes Nodes { get; }
vb
<Browsable(False)>
Public Overridable ReadOnly Property Nodes As TreeListNodes

Property Value

TypeDescription
TreeListNodes

A TreeListNodes object representing the node’s child nodes collection.

|

Remarks

Nodes of the Tree List control are represented in a tree-like structure. This implies that each node can have a number of child nodes. Each child can have its own child nodes collection, etc. This collection can be accessed via the Nodes property of a node. The collection of root nodes can be obtained by reading the TreeList.Nodes property value.

The Nodes property returns the TreeListNodes object whose properties and methods can be used to add, delete and access individual nodes within the collection.

The organization of nodes described above implies that you must write recursive code to traverse through all nodes. However, the Tree List control allows you to avoid writing such code. It provides a nodes iterator that can be used to visit each node of the predefined set and perform the specified operation on them. Please refer to the TreeList.NodesIterator property description for details on using the iterator.

Example

The code below selects all nodes located at the second nesting level (root node children).

csharp
treeList1.BehaviorOptions |= BehaviorOptionsFlags.MultiSelect;
ArrayList al = new ArrayList();
for (int i = 0; i < treeList1.Nodes.Count; i++) {
   IEnumerator en = treeList1.Nodes[i].Nodes.GetEnumerator();
   while(en.MoveNext())
      al.Add(en.Current);
}
treeList1.Selection.Set(al);
vb
TreeList1.BehaviorOptions = TreeList1.BehaviorOptions Or BehaviorOptionsFlags.MultiSelect
Dim al As New ArrayList()
Dim i As Integer
For i = 0 To TreeList1.Nodes.Count - 1
   Dim en As IEnumerator = TreeList1.Nodes(i).Nodes.GetEnumerator()
   While (en.MoveNext())
      al.Add(en.Current)
   End While
Next
TreeList1.Selection.Set(al)

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

winforms-treelist-sync-position-of-nodes-with-data-records/CS/Q351285/Form1.cs#L50

csharp
foreach (TreeListNode n in ns) {
    UpdateNodesPositions(n.Nodes);
    n.TreeList.SetNodeIndex(n, Convert.ToInt32(n.GetValue("Order")));

drag-drop-grid-rows-to-treelist/CS/DragAndDropRows/Form1.cs#L103

csharp
return -1000;
var nodes = destNode.ParentNode == null ? treeList.Nodes : destNode.ParentNode.Nodes;
int index = nodes.IndexOf(destNode);

winforms-treelist-copy-nodes-to-another-treelist/CS/CopyNodesExample/MainForm.cs#L63

csharp
foreach (TreeListNode node in operation.SourceNode.Nodes.Reverse()) {
    stack.Push((node, newNode.Nodes));
}

winforms-treelist-custom-check-nodes-behavior/CS/Example/TreeListCheckHelper.cs#L21

csharp
{
    foreach(TreeListNode childNode in node.Nodes)
        if(childNode.CheckState == CheckState.Checked)

winforms-treelist-sync-position-of-nodes-with-data-records/VB/Q351285/Form1.vb#L62

vb
For Each n As TreeListNode In ns
    UpdateNodesPositions(n.Nodes)
    n.TreeList.SetNodeIndex(n, Convert.ToInt32(n.GetValue("Order")))

drag-drop-grid-rows-to-treelist/VB/DragAndDropRows/Form1.vb#L99

vb
If e.InsertType = InsertType.AsChild Then Return -1000
Dim nodes = If(destNode.ParentNode Is Nothing, treeList.Nodes, destNode.ParentNode.Nodes)
Dim index As Integer = nodes.IndexOf(destNode)

winforms-treelist-copy-nodes-to-another-treelist/VB/CopyNodesExample/MainForm.vb#L67

vb
For Each node As TreeListNode In operation.SourceNode.Nodes.Reverse()
    stack.Push((node, newNode.Nodes))
Next

winforms-treelist-custom-check-nodes-behavior/VB/Example/TreeListCheckHelper.vb#L18

vb
Private Function AnyChildIsChecked(ByVal node As TreeListNode) As Boolean
    For Each childNode As TreeListNode In node.Nodes
        If childNode.CheckState = CheckState.Checked Then

See Also

Nodes

HasChildren

NodesIterator

GetNodeList()

Nodes

TreeListNode Class

TreeListNode Members

DevExpress.XtraTreeList.Nodes Namespace