Back to Devexpress

TreeViewControl.Nodes Property

wpf-devexpress-dot-xpf-dot-grid-dot-treeviewcontrol-3e968757.md

latest3.7 KB
Original Source

TreeViewControl.Nodes Property

Gets the collection of root nodes.

Namespace : DevExpress.Xpf.Grid

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

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public TreeListNodeCollection Nodes { get; }
vb
Public ReadOnly Property Nodes As TreeListNodeCollection

Property Value

TypeDescription
TreeListNodeCollection

The collection of root nodes.

|

Remarks

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

xaml
<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 nodes. You can specify a start node or the collection of nodes, and whether to process only visible nodes.

Note

If you specified the 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.

xaml
<dxg:TreeViewControl x:Name="treeview"
                     Loaded="treeview_Loaded"
                     ... />
csharp
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);
}
vb
Private Sub SmartExpandNodes(ByVal minChildCount As Integer)
    For Each node As DevExpress.Xpf.Grid.TreeListNode In New DevExpress.Xpf.Grid.TreeListNodeIterator(treeview.Nodes, True)
        node.IsExpanded = node.Nodes.Count >= minChildCount
    Next
End Sub

Private Sub treeview_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    SmartExpandNodes(3)
End Sub

See Also

TreeViewControl Class

TreeViewControl Members

DevExpress.Xpf.Grid Namespace