Skip to main content
A newer version of this page is available. .

How to: Iterate Through Nodes via the Node Iterator

  • 6 minutes to read

This example shows how to traverse through all visible nodes and expand only those nodes that have more than four child nodes. Nodes that have less than four child nodes are collapsed.

View Example

Imports Microsoft.VisualBasic
Imports System.Windows
Imports DevExpress.Xpf.Grid

Namespace DXTreeList_NodeTraversing
    ''' <summary>
    ''' Interaction logic for MainWindow.xaml
    ''' </summary>
    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
            treeListControl1.ItemsSource = Stuff.GetStuff()
        End Sub

        Private Sub treeListControl1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            SmartExpandNodes(4)
        End Sub

        Private Sub SmartExpandNodes(ByVal minChildCount As Integer)
            Dim nodeIterator As New TreeListNodeIterator(treeListView1.Nodes, True)
            Do While nodeIterator.MoveNext()
                nodeIterator.Current.IsExpanded = nodeIterator.Current.Nodes.Count >= minChildCount
            Loop
        End Sub
    End Class
End Namespace