Click here to Skip to main content
15,885,915 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
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
Updated 13-Feb-13 4:12am
v3

1 solution

When you are populating the treeview create the tag when you add the node...
VB
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
 
Share this answer
 
v2
Comments
Chris Reynolds (UK) 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900