Folders as Treeview

mmjrules
01-03-2005, 08:24 AM
I searched the forum but didn't find something that could help me!

I'm continuing an installer interface for a CD with freeware programs.

The programs are placed in folders according to their use i.e. "Messaging","Security",etc and every program has it's own subfolder.

Then, to create a treeview control for the user to select the program he wants,I have to make a txt file like this

[Chat-Messaging]
CuSeeMe=\chat-messaging\cuseeme\cuseeme.exe
ICQ Pro 2003=\chat-messaging\icqpro2003a\icqpro2003a.exe
mIRC v6=\chat-messaging\mIRC612\mirc612.exe


The program reads the txt file and creates the treeview. [] denote parent nodes and everything under that are childer nodes

The problem is that when I want to put new programs,I have to make the txt file all over again.

I would like simply to put the programs in folders and then make the treeview directly from that and simply name all the programs setup.exe i.e.(all are folders,indent=subfolder)

Messaging
MSN Messenger
Yahoo Messenger
Trillian
Network
Zone Alarm
....
etc


The txt solution is not mine and I have no clue how to use the treeview control!

Please help me! :(

robertg
01-03-2005, 12:05 PM
TreeView Tutorial (http://abstractvb.com/code/code719.asp)
Edit, Save and Load Treeview Data (http://www.vb-helper.com/howto_treeview_save_load.html)

mmjrules
01-04-2005, 06:12 AM
Fixed it and here's the solution

Private Sub UserForm_Initialize()
Dim nodx As Node
Dim nody As Node

Dim MyFile, MyPath, MyName, MySub
Dim i As Integer
Dim d, j As Integer
i = 1
j = 1

Set TreeView1.ImageList = ImageList1



MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory)
MySub = Dir((MyPath & MyName & "\"), vbDirectory)
On Error Resume Next

Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Display entry only if it
Set nodx = TreeView1.Nodes.Add(, , , MyName, "Closed")
i = i + 1
Do While MySub <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MySub <> "." And MySub <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName & "\" & MySub) And vbDirectory) = vbDirectory Then

Set nody = TreeView1.Nodes.Add(nodx, tvwChild, , MySub, "Closed")
i = i + 1
End If
End If
MySub = Dir
Loop

End If ' it represents a directory.
End If

MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
For d = 1 To j
MyName = Dir ' Get next entry.
Next d
j = j + 1
MySub = Dir((MyPath & MyName & "\"), vbDirectory)

Loop

End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum