Using vb2005, I have a treeview on a form, and I'm trying to populate the nodes with drives and directories and files. I got the drives to populate fine, but when it comes to directories, so far the best I can do is to have it populate the drives all over again for each drive listed when I double-click a node.
If I use the following code:
For Each drv As Object In My.Computer.FileSystem.Drives()
tvwDir.Nodes(0).Nodes.Add(drv.ToString)
Next
For Each node As TreeNode In tvwDir.Nodes
For Each dir As Object In My.Computer.FileSystem.GetDirectories(node.Text)
If My.Computer.FileSystem.DirectoryExists(dir.ToString) Then
node.Nodes.Add(dir.ToString)
End If
Next
Next ...it runs filling up the treeview until it says directory not found. The path it lists is about 10 directories deep, but the last part is \My Computer. This is perplexing me to no end, and I am having trouble finding detailed information on using the treeview object. Can anybody help? I'm sure there's a better way because it seems it's not just getting the 1st level directories but all directories, at least on that drive.