?
Solved

vb6 treeview child nodes added to listbox

Posted on 2005-03-09
2
Medium Priority
?
579 Views
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!



Root
 Child1
 Child2
 etc..
0
Comment
Question by:bluedragon99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 86

Expert Comment

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

            ' OR

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

Accepted Solution

by:
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.Clear
        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
        Else
            done = True
        End If
    Loop
End Sub
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 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