vb6 treeview child nodes added to listbox

Posted on 2005-03-09
Medium Priority
Last Modified: 2012-06-27
I need to add child nodes from a treeview control to a list box.  I need to loop through them somehow?  HELP!

Question by:bluedragon99
  • 2
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13498760
Private Sub Command1_Click()
    Dim n As MSComctlLib.Node
    For Each n In TreeView1.Nodes
            List1.AddItem n.Text

            ' OR

            List1.AddItem n.FullPath
    Next n
End Sub
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 13498992
Or if you wanted to add the selected node and all of its children to the listbox then:

Private Sub Command3_Click()
    Dim nodex As MSComctlLib.Node
    Set nodex = TreeView1.SelectedItem
    If Not (nodex Is Nothing) Then
        List1.AddItem nodex.FullPath
        enumChildren nodex.Child
    End If
End Sub

Private Sub enumChildren(ByVal nodex As MSComctlLib.Node)
    Dim curNode As MSComctlLib.Node
    Dim done As Boolean
    If nodex Is Nothing Then
        Exit Sub
    End If
    done = False
    Set curNode = nodex.FirstSibling
    Do While Not done
        List1.AddItem curNode.FullPath
        If curNode.Children > 0 Then
            enumChildren curNode.Child
        End If
        If curNode.Key <> curNode.LastSibling.Key Then
            Set curNode = curNode.Next
            done = True
        End If
End Sub

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question