Search code examples
visual-studio-2008devexpressxtratreelist

How to traverse the nodes for a DevExpress.XtraTreeList.TreeList


I am trying to traverse the nodes of the DevExpress.XtraTreeList.TreeList and it isn't working.

Basically all I have is the caption and value of the node I want to look for. Is there a simple way I can find it. After it is found I am just moving the focus to the new node and I already know how to do that if I have the proper index.

Thanks


Solution

  • I ended up using a Queue and then going through the TreeList using the current node's tree.nodes.

    Dim text As String = "looking for this"
    Dim myQueue As New Queue
    For i As Integer = 0 To tree.Nodes.Count - 1
        If tree.Nodes(i).GetDisplayText("name").Equals(text ) Then
              tree.SetFocusedNode(tree.Nodes(i))
              Exit Sub
        Else
              If tree.Nodes(i).HasChildren Then
                   myQueue.Enqueue(tree.Nodes(i))
              End If
        End If
    Next
    
    While myQueue.Count > 0
        Dim tempNode As DevExpress.XtraTreeList.Nodes.TreeListNode = CType(myQueue.Dequeue, DevExpress.XtraTreeList.Nodes.TreeListNode)
        For i As Integer = 0 To tempNode.Nodes.Count - 1
              If tempNode.Nodes(i).GetDisplayText("name").Equals(e.Button.Caption) Then
                  tree.SetFocusedNode(tempNode.Nodes(i))
                  Exit Sub
              Else
                  If tempNode.Nodes(i).HasChildren Then
                       myQueue.Enqueue(tempNode.Nodes(i))
                  End If
              End If
        Next
    End While