Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - treeview node.ToString problem

Reply
 
Old 08-07-2008   #1 (permalink)
markvbuser


 
 

treeview node.ToString problem

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.

My System SpecsSystem Spec
Old 08-07-2008   #2 (permalink)
Jeff Gaines


 
 

Re: treeview node.ToString problem

On 07/08/2008 in message
<96189f63-415e-4bdc-83d4-475139669608@xxxxxx>
markvbuser wrote:
Quote:

>How can i get the value without stripping the unwanted text ?
It may be easier to set the Tag of each node to the Path of the Directory
that it refers to, e.g.

tnNew = new TreeNode(DirecotryName, iconIndex, selectedIconIndex)
tnNew.Tag = Directory Path.

Then you can get the Path you need:

string newPath = (string)e.Node.Tag

(you may need to juggle this into VB)

You could also use the FullPath property of the TreeNode but that won't
work if you have a root node with the computer name, or if you use drive
names rather than drive paths in your display.

--
Jeff Gaines Damerham Hampshire UK
There is absolutely no substitute for a genuine lack of preparation
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
get child node of selected parent node .NET General
$var.ToString() Misunderstanding PowerShell
treeview multiselect problem .NET General
problem with multiselect treeview nodes .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46