Click here to Skip to main content
Rate this: bad
good
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 4:44am
al3abby429
Edited 13-Feb-13 5:12am
CHill6067.4K
v3

1 solution

Rate this: bad
good
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
  Permalink  
v2
Comments
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 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
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