Hi All,
I am trying to populate a treeview with directories and subdirectories, I do not care about files. In fact this is why I can not use the openFile object. I do not have a file to get the full path name from.
here is the code I am using
Private Sub FindAllDir()
Dim strDir As String()
Dim strDirChild() As String
Dim oNode As New System.Windows.Forms.TreeNode
strDir = Directory.GetLogicalDrives
Dim strOne, strOneChild As String
For Each strOne In strDir
cmbDir.Items.Add(strOne)
oNode.ImageIndex = 0
oNode.SelectedImageIndex = 1
trvMain.Nodes.Add(strOne)
Try
If System.IO.Directory.GetDirectories(strOne).Length > 0 Then
strDirChild = System.IO.Directory.GetDirectories(strOne)
For Each strOneChild In strDirChild
Call FindAllDir()
Next
End If
Catch ex As Exception
'Catch ex As DirectoryNotFoundException
'Catch ex As FileNotFoundException
End Try
Next
'cmbdir.SelectedIndex = cmbdir.
End Sub
the treeview gets populated with the logical drives on my computer. I then need the code to look for subdirectories.
the inside "For" loop (where I call the function again) causes the program to loop forever. I think I am close with this code, I just can't get the final steps down.
I have searched for solutions to this problem but I just can't get the examples to work for me. so I started working on my own code.
thanks in advanced for any solutions and examples!
Ronze
I am trying to populate a treeview with directories and subdirectories, I do not care about files. In fact this is why I can not use the openFile object. I do not have a file to get the full path name from.
here is the code I am using
Private Sub FindAllDir()
Dim strDir As String()
Dim strDirChild() As String
Dim oNode As New System.Windows.Forms.TreeNode
strDir = Directory.GetLogicalDrives
Dim strOne, strOneChild As String
For Each strOne In strDir
cmbDir.Items.Add(strOne)
oNode.ImageIndex = 0
oNode.SelectedImageIndex = 1
trvMain.Nodes.Add(strOne)
Try
If System.IO.Directory.GetDirectories(strOne).Length > 0 Then
strDirChild = System.IO.Directory.GetDirectories(strOne)
For Each strOneChild In strDirChild
Call FindAllDir()
Next
End If
Catch ex As Exception
'Catch ex As DirectoryNotFoundException
'Catch ex As FileNotFoundException
End Try
Next
'cmbdir.SelectedIndex = cmbdir.
End Sub
the treeview gets populated with the logical drives on my computer. I then need the code to look for subdirectories.
the inside "For" loop (where I call the function again) causes the program to loop forever. I think I am close with this code, I just can't get the final steps down.
I have searched for solutions to this problem but I just can't get the examples to work for me. so I started working on my own code.
thanks in advanced for any solutions and examples!
Ronze