Results 1 to 17 of 17

Thread: Walk through treeview. How?

Threaded View

  1. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Walk through treeview. How?

    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.
    Name:  untitled.GIF
Views: 1349
Size:  3.3 KB
    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
    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
    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.
    Last edited by LaVolpe; Jan 26th, 2010 at 04:28 PM. Reason: made it a bit shorter
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width