Click here to Skip to main content
11,789,710 members (64,143 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: XML VB.NET Treeview
Hi everyone

I 'm Using the class from this example

Using Serialization to Persist TreeView Control (VB.NET)[^]

to populate a treeview from a xml file and then save it once again
I can add, remove treenodes and save them to the xml file.

But what I want to do and don't know how is that:

- I want the treeview nodes to have a tag property and I want this tag to hold some text
- I want the tag property's text to load in a textbox so I can edit it and save it along with other treenode properties
i tried so many things but none of them worked untile my mind got stuck.
I highly appreciated if someone can show me how it's done or point me to the right direction
Posted 13-Feb-13 3:44am
Edited 13-Feb-13 4:12am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

When you are populating the treeview create the tag when you add the node...
Dim tn As TreeNode
tn = treeView.Nodes.Add(Me.Nodes(i).ToTreeNode)
tn.Tag = i 'Whatever it is that you want in the tag
Then read the tag on an appropriate event (e.g. click or afterselect etc)
Me.TextBox1.Text = (e.Node.Tag)
or update it
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
	If Me.TreeView1.SelectedNode Is Nothing Then
		Exit Sub
	End If
	Me.TreeView1.SelectedNode.Tag = Me.TextBox1.Text
End Sub
Chris Reynolds (BNY) at 13-Feb-13 11:02am
Looking at the serialization code being linked to it already loads and saves the tag for each node so you probably only need the second two code segments .
al3abby at 13-Feb-13 13:37pm
You're right!!! Thank you very much Chris
And of course a big Thanks to you Chill60

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 999
1 Maciej Los 765
2 KrunalRohit 686
3 CPallini 606
4 Richard MacCutchan 430

Advertise | Privacy | Mobile
Web01 | 2.8.1509028.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100