treeview node.ToString problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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_BeforeExpand(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles
TreeView1.BeforeExpand

Me.TreeView1.SelectedNode = e.Node
getsubDirectories(e.Node)

End Sub
--------------------------------------------------------------------------------------------------------------------------

Then i'm passing the selected node to this subroutine:

---------------------------------------------------------------------------------------------------------------------------
Public Sub getsubDirectories(ByVal baseNode)

Dim subDirectories() As String
Dim myNodeCollection As TreeNodeCollection =
Form1.TreeView1.SelectedNode.Nodes
Dim basePath As String = Replace(baseNode.ToString, "TreeNode:
", "")

For Each subNode In myNodeCollection
Dim subdirectoryPath As String = Replace(subNode.ToString,
"TreeNode: ", "")
Dim thisPath As String = basePath & subdirectoryPath

Try
subDirectories = Directory.GetDirectories(thisPath)
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.
.



Relevant Pages

  • Re: ChDrive and ChPath to a network drive
    ... ChDrive and ChDir are limited to those mapped drives. ... Sub ChDirNet(szPath As String) ... Dim myFileName As Variant ... although this workbook might also be used in 2007. ...
    (microsoft.public.excel.programming)
  • Re: Checking multiple locations for folder using IF statement
    ... I am not seeing the problem, Ron. ... It will loop through all drives from L: to Z: looking ... Dim fixedpath As String ... So, what I'm trying to do is open a folder, if it exists. ...
    (microsoft.public.access.formscoding)
  • Re: Checking multiple locations for folder using IF statement
    ... It will loop through all drives from L: to Z: looking ... Dim fixedpath As String ... Dim blnFoundPath ... So, what I'm trying to do is open a folder, if it exists. ...
    (microsoft.public.access.formscoding)
  • Re: Complicated mapping drive question/please proof
    ... dim test:test = true ... DriveExists = False ... Also, I needed to reconfigure the script you suggested so that it mapped the next available drive letter, starting at the driveLetter parameter entered in the parameters field in the GPO box. ... This code removes all currently mapped drives then maps a share to the drive. ...
    (microsoft.public.scripting.vbscript)
  • Re: Checking multiple locations for folder using IF statement
    ... It will loop through all drives from L: to Z: looking ... Dim fixedpath As String ... Dim blnFoundPath ... So, what I'm trying to do is open a folder, if it exists. ...
    (microsoft.public.access.formscoding)