Hi all,
I'm just learning vb2008 and i have a problem, I'm populating a
treeview with a hard drive
directory structure. This is my code:
I've populated the treeview with the available drives and the first
level of directories for each drive.
Then I'm using this code to get the selected node when the user
expands the node
--------------------------------------------------------------------------------------------------------------------------
Private Sub TreeView1_Befor eExpand(ByVal sender As System.Object,
ByVal e As System.Windows. Forms.TreeViewC ancelEventArgs) Handles
TreeView1.Befor eExpand
Me.TreeView1.Se lectedNode = e.Node
getsubDirectori es(e.Node)
End Sub
--------------------------------------------------------------------------------------------------------------------------
Then i'm passing the selected node to this subroutine:
---------------------------------------------------------------------------------------------------------------------------
Public Sub getsubDirectori es(ByVal baseNode)
Dim subDirectories( ) As String
Dim myNodeCollectio n As TreeNodeCollect ion =
Form1.TreeView1 .SelectedNode.N odes
Dim basePath As String = Replace(baseNod e.ToString, "TreeNode:
", "")
For Each subNode In myNodeCollectio n
Dim subdirectoryPat h As String = Replace(subNode .ToString,
"TreeNode: ", "")
Dim thisPath As String = basePath & subdirectoryPat h
Try
subDirectories = Directory.GetDi rectories(thisP ath)
For Each thisDirectory In subDirectories
'add node to treeview
Next
Catch ex As Exception
End Try
Next
End Sub
----------------------------------------------------------------------------------------------------------------------------------
If the user expands the C drive the value for the selected node
contains "TreeNode: "
eg. TreeNode:C\:
and i need to strip the unwanted text to provide a valid path for
getdirectories.
How can i get the value without stripping the unwanted text ?
regards.
I'm just learning vb2008 and i have a problem, I'm populating a
treeview with a hard drive
directory structure. This is my code:
I've populated the treeview with the available drives and the first
level of directories for each drive.
Then I'm using this code to get the selected node when the user
expands the node
--------------------------------------------------------------------------------------------------------------------------
Private Sub TreeView1_Befor eExpand(ByVal sender As System.Object,
ByVal e As System.Windows. Forms.TreeViewC ancelEventArgs) Handles
TreeView1.Befor eExpand
Me.TreeView1.Se lectedNode = e.Node
getsubDirectori es(e.Node)
End Sub
--------------------------------------------------------------------------------------------------------------------------
Then i'm passing the selected node to this subroutine:
---------------------------------------------------------------------------------------------------------------------------
Public Sub getsubDirectori es(ByVal baseNode)
Dim subDirectories( ) As String
Dim myNodeCollectio n As TreeNodeCollect ion =
Form1.TreeView1 .SelectedNode.N odes
Dim basePath As String = Replace(baseNod e.ToString, "TreeNode:
", "")
For Each subNode In myNodeCollectio n
Dim subdirectoryPat h As String = Replace(subNode .ToString,
"TreeNode: ", "")
Dim thisPath As String = basePath & subdirectoryPat h
Try
subDirectories = Directory.GetDi rectories(thisP ath)
For Each thisDirectory In subDirectories
'add node to treeview
Next
Catch ex As Exception
End Try
Next
End Sub
----------------------------------------------------------------------------------------------------------------------------------
If the user expands the C drive the value for the selected node
contains "TreeNode: "
eg. TreeNode:C\:
and i need to strip the unwanted text to provide a valid path for
getdirectories.
How can i get the value without stripping the unwanted text ?
regards.
Comment