Heath said:
I put some data into a .tag property of a node for a treeview control,
but want to be able to store more data in other properties such as
.tag2, .tag3 etc..
Is this possible to do? Can I add my own properties to an existing
control ?
No, but you can extend the TreeNode class so it contains whatever you
want it to have:
Class CustomLeaf
Inherits TreeNode
Public Sub New()
MyBase.New()
End Sub
' One new property
Public Property S1() as String ' say
Get/Set
End Property
' And another
Public Property Font() as System.Drawing.Font 'say
Get/Set
End Property
' ... as far as you like ...
End Class
.... then ...
Dim oCL as New CustomLeaf()
Me.TreeView1.Nodes.Add( oCL )
or
Me.TreeView1.Nodes(0).Nodes(2).Nodes(3).Add( oCL )
Whatever you can do with the TreeNode, you can do with your customised one.
Possibly OTT, but I'll throw it in anyway ...
If you're using a tree to display some "collection" of related objects,
have each object provide [a property that returns] a customised
"TreeNode" but give that TreeNode a reference back to the original
object, something like
Class LinkedThing
Public Function GetTreeNode() as ViewerNode
Return New ViewerNode( Me )
End Function
End Class
Class ViewerNode
Inherits TreeNode
Private Sub New()
End Sub
Friend Sub New( byVal source as LinkedThing )
m_source = source
MyBase.Text = source.Text ' say
End Sub
Public ReadOnly Property Source() as LinkedThing
Get
Return m_source
End Get
End Property
End Class
This way, you can access properties of objects in your "main" collection
(which may be of a totally different Type, inheriting from something
totally different), but still view and arrange them in a tree structure.
Just a thought.
HTH,
Phill W.