wpf-devexpress-dot-xpf-dot-grid-dot-treeviewcontrol-3e968757.md
Gets the collection of root nodes.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public TreeListNodeCollection Nodes { get; }
Public ReadOnly Property Nodes As TreeListNodeCollection
| Type | Description |
|---|---|
| TreeListNodeCollection |
The collection of root nodes.
|
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.
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.
<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);
}
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