Create Treeview Nodes based on string

Hi,

I have around 20,000 records in a text file. Each line contains something like the following:

   Microwave Ovens\Samsung\FC139STFC\20050809091926296_1.Precaution.pdf
   Microwave Ovens\LG\MS6682NL\Exploded_view.pdf
   Microwave Ovens\LG\Ms324sce Ms325sce\Parts Lists\MS325SCE.csv

   Each of the above is followed by comma delimited date, time, filesize etc

  I need to create Parent/Child nodes in a Treeview using this info. For example,

     Microwave Ovens
       \Samsung
       \FC139STFC
           
   Then populate a Listview with the filename i.e 20050809091926296_1.Precaution.pdf  

   Does anyone have some sample code that demonstrates this, please.

Thanks.

TJ
tvtechAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
It's fairly straight forward to do this but I don't know how practical it would be as I'm not sure a TreeView can handle that many nodes.  At the very least it would certainly be tedious for a human to have to filter thru that many records...
tvtechAuthor Commented:
If you have some source code, by all means please post it, as I can always mod the code later to import the text file into a MDB. Humans don't need to filter the data, as a search facility will be added later. The main thing is to make it work.

Thanks.

TJ
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Here's the gist of it...

Option Explicit

Private Sub Form_Load()
    On Error Resume Next
   
    Dim ff As Integer
    Dim fileName As String
    Dim inputLine As String
    Dim values As Variant
    Dim nodes As Variant
    Dim Node As String
    Dim i As Integer
    Dim n As Node
    Dim parentN As Node
   
    ff = FreeFile
    fileName = "c:\someFile.txt"
    Open fileName For Input As #ff
    While Not EOF(ff)
        Line Input #ff, inputLine
        values = Split(inputLine, ",")
        nodes = Split(values(0), "\")
       
        Set parentN = Nothing
        For i = 0 To UBound(nodes)
            If i < UBound(nodes) Then
                Set n = Nothing
                Set n = TreeView1.nodes(nodes(i))
                If n Is Nothing Then
                    If parentN Is Nothing Then
                        Set n = TreeView1.nodes.Add(, , nodes(i), nodes(i))
                    Else
                        Set n = TreeView1.nodes.Add(parentN, tvwChild, nodes(i), nodes(i))
                    End If
                End If
                Set parentN = n
            Else
                parentN.Tag = nodes(i)
            End If
        Next i
    Wend
    Close #ff
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    If Node.Tag <> "" Then
        Debug.Print Node.Tag
    End If
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tvtechAuthor Commented:
Idle_Mind, nice work. Many thanks.

TJ
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.