wpf-devexpress-dot-xpf-dot-grid-a4ea5447.md
The Node Iterator.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public class TreeListNodeIterator :
IEnumerator<TreeListNode>,
IDisposable,
IEnumerator,
IEnumerable<TreeListNode>,
IEnumerable
Public Class TreeListNodeIterator
Implements IEnumerator(Of TreeListNode),
IDisposable,
IEnumerator,
IEnumerable(Of TreeListNode),
IEnumerable
The Node Iterator allows you to traverse through the nodes without writing recursive code. Nodes are visited one by one, starting from a specified node down to the last node contained within a tree.
To iterate through the nodes, do the following.
Create a new instance of the TreeListNodeIterator class. Multiple constructors allow you to specify a start node or a collection of nodes, along with whether to process only visible nodes.
Use the TreeListNodeIterator.MoveNext method to iterate through nodes. The currently processed node is returned by the TreeListNodeIterator.Current property. Each time the TreeListNodeIterator.MoveNext method is called, the Node Iterator moves to the next node in the hierarchy, and updates the TreeListNodeIterator.Current property. If the current node is the last node, the TreeListNodeIterator.MoveNext method returns false.
To learn more, see Iterating Through Nodes.
This example shows how to traverse through all visible nodes to expand ones that have 4 or more child nodes. Nodes that have less than 4 child nodes are collapsed.
View Example: Iterate Through Nodes With the TreeListNodeIterator
<dxg:GridControl x:Name="grid"
AutoGenerateColumns="AddNew"
EnableSmartColumnsGeneration="True"
Loaded="OnGridLoaded">
<dxg:GridControl.View>
<dxg:TreeListView x:Name="view" AutoWidth="True"
KeyFieldName="ID" ParentFieldName="ParentID"/>
</dxg:GridControl.View>
</dxg:GridControl>
void SmartExpandNodes(int minChildCount) {
TreeListNodeIterator nodeIterator = new TreeListNodeIterator(view.Nodes, true);
while (nodeIterator.MoveNext())
nodeIterator.Current.IsExpanded = nodeIterator.Current.Nodes.Count >= minChildCount;
}
void OnGridLoaded(object sender, RoutedEventArgs e) {
SmartExpandNodes(4);
}
Private Sub SmartExpandNodes(ByVal minChildCount As Integer)
Dim nodeIterator As TreeListNodeIterator = New TreeListNodeIterator(Me.view.Nodes, True)
While nodeIterator.MoveNext()
nodeIterator.Current.IsExpanded = nodeIterator.Current.Nodes.Count >= minChildCount
End While
End Sub
Private Sub OnGridLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
SmartExpandNodes(4)
End Sub
Object TreeListNodeIterator
See Also