All docs
V20.2
21.1 (EAP/Beta)
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

TreeViewControl.Nodes Property

Gets the collection of root nodes.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v20.2.dll

Declaration

public TreeListNodeCollection Nodes { get; }

Property Value

Type Description
TreeListNodeCollection

The collection of root nodes.

Remarks

You can use the Nodes property to create an unbound tree without a data source:

<dxg:TreeViewControl AutoExpandAllNodes="True">
    <dxg:TreeViewControl.Nodes>
        <dxg:TreeListNode Content="Root Node 1">
            <dxg:TreeListNode.Nodes>
                <dxg:TreeListNode Content="Level 1">
                    <dxg:TreeListNode.Nodes>
                        <dxg:TreeListNode Content="Level 2"/>
                    </dxg:TreeListNode.Nodes>
                </dxg:TreeListNode>
            </dxg:TreeListNode.Nodes>
        </dxg:TreeListNode>
        <dxg:TreeListNode Content="Root Node 2">
            <dxg:TreeListNode.Nodes>
                <dxg:TreeListNode Content="Level 1"/>
            </dxg:TreeListNode.Nodes>
        </dxg:TreeListNode>
    </dxg:TreeViewControl.Nodes>
</dxg:TreeViewControl>

Specify the TreeViewFieldName property to display data in the TreeViewControl if you set an object as a node's content.

Iterate Through Nodes

Create a new instance of the TreeListNodeIterator class to iterate through the nodes. You can specify a start node or a collection of nodes, along with whether to process only visible nodes.

NOTE

If you specified a collection of nodes, the Node Iterator starts to process nodes from the first node in the specified collection.

The following code sample iterates through all visible nodes to expand nodes that have more than three child nodes.

<dxg:TreeViewControl x:Name="treeview"
                     Loaded="treeview_Loaded"
                     ... />
void SmartExpandNodes(int minChildCount) {
    foreach (DevExpress.Xpf.Grid.TreeListNode node in new DevExpress.Xpf.Grid.TreeListNodeIterator(treeview.Nodes, true)) {
        node.IsExpanded = node.Nodes.Count >= minChildCount;
    }
}
void treeview_Loaded(object sender, RoutedEventArgs e) {
    SmartExpandNodes(3);
}
See Also