Skip to main content
A newer version of this page is available. .
All docs
V20.2

TreeViewControl.Nodes Property

Gets the collection of root nodes.

Namespace: DevExpress.Xpf.Grid

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

NuGet Packages: DevExpress.WindowsDesktop.Wpf.Grid.Core, DevExpress.Wpf.Grid.Core

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