Re: Treeview Tag and object
Try doing the same but use a class instead of a structure. That way, you'll get a reference to the object stored in the node tag. My guess would be that sgData = CType(nde.Tag, SG_DATA) creates a copy of the structure instead of passing you a reference to it, something that doesn't happen for an object.
Cheers,
NTG
Re: Treeview Tag and object
A structure is a Value not a class, so basically when you access or assign it, you're accessing/assigning a copy of it, not a reference to it, so you need to get the structure value from the Tag, alter it, then reassign it to the Tag, i.e.
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim node As TreeNode
Dim struct As MyStruct
For i = 1 To 10
node = TreeView1.Nodes.Add("Node " & i)
struct.Property1 = "Node " & i
node.Tag = struct
Next
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim struct As MyStruct = e.Node.Tag
TextBox1.Text = struct.Property1
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim struct As MyStruct
If Not TreeView1.SelectedNode Is Nothing Then
struct = TreeView1.SelectedNode.Tag
struct.Property1 = TextBox1.Text
TreeView1.SelectedNode.Tag = struct
End If
End Sub
Public Structure MyStruct
Public Property1 As String
End Structure
Treeview Tag and object - resolved
Thanks guys, that is exactly the problem.
I am getting a new version of object and I do not get a reference to the structure. So the solution is just to reassign it, after I have changed it.
Thank for the great help.