Try this. Tested on this type of structure & worked well. Nodes were not added in topographical order either; just like in real life where the child nodes may be added well after the parent nodes have been added.
1. Use a timer for testing, set its interval about 1/2 second
2. Ensure TreeView1.HideSelection = False
3. Ensure the root node is selected first then enable the timer
The code is set to go around & around from top to bottom, again and again. While it is running, you can click on any node to set the current starting position.Code:Private Sub Timer1_Timer() Dim tNode As Node Set tNode = TreeView1.SelectedItem If tNode.Children Then ' has child nodes; move to 1st child Set tNode = tNode.Child.FirstSibling ElseIf tNode.Next Is Nothing Then ' gotta move up level(s) Set tNode = tNode.Parent Do Until tNode Is Nothing ' if Nothing, then done If Not tNode.Next Is Nothing Then Set tNode = tNode.Next Exit Do End If Set tNode = tNode.Parent ' move up again Loop Else Set tNode = tNode.Next ' move to next sibling End If If tNode Is Nothing Then ' keep looping around & around until you stop the timer Set TreeView1.SelectedItem = TreeView1.Nodes(1).Root Else Set TreeView1.SelectedItem = tNode End If End Sub




Reply With Quote