vicmart69
asked on
Add properties and numbering to Treeview
HI,
I'm using a treeview control which is being feed by a database. The tag property is already used to define relationship among nodes (Node's Unique Identifier) so it's of no use. I would like to:
A- Be able to show numbers in front of every nodes, dynamically generated upon their rank in treeview ex:
1.0 Parent Node
1.1 Child node
1.2 Child Node
2.0 Parent Node .....
B- Make sure nodes are sorted even if I drag&drop a node elsewhere in the treeview(then entire numbering has to be redefined)
C- I would like to save the "number" in the database as well as to add a description of the node in the database. ie: is it possible to add properties to the treeview (like a description and the number)?
Thanks
I'm using a treeview control which is being feed by a database. The tag property is already used to define relationship among nodes (Node's Unique Identifier) so it's of no use. I would like to:
A- Be able to show numbers in front of every nodes, dynamically generated upon their rank in treeview ex:
1.0 Parent Node
1.1 Child node
1.2 Child Node
2.0 Parent Node .....
B- Make sure nodes are sorted even if I drag&drop a node elsewhere in the treeview(then entire numbering has to be redefined)
C- I would like to save the "number" in the database as well as to add a description of the node in the database. ie: is it possible to add properties to the treeview (like a description and the number)?
Thanks
It will get messy.. I think the Tag is the best place. You know you can tag any object to a node so why not have the tag define the relationship AND store the node's unique id AND the number AND the text?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I hope you can find out one limitation of the code
It will fail if you have a Dash " - " in the actual text of the node
I hope that will not be a big problem though
what you can do is use any other character in place of dash which your nodes will not have, better still you can pass the cahracter as an argument to the function so that it uses that particular cahracter it will help modularize the code, so that it can be used for any tree
It will fail if you have a Dash " - " in the actual text of the node
I hope that will not be a big problem though
what you can do is use any other character in place of dash which your nodes will not have, better still you can pass the cahracter as an argument to the function so that it uses that particular cahracter it will help modularize the code, so that it can be used for any tree
>>is it possible to add properties to the treeview (like a description and the number)?
Alternatively, yes you can extend any object and add whatever you like.
Public Class SpecialTreeView
Inherits System.Windows.Forms.TreeN ode
Dim _descript As String
Dim _id As String
Public Property ID() As String
Get
Return _id
End Get
Set(ByVal Value As String)
_id = Value
End Set
End Property
Public Property Descript() As String
Get
Return _descript
End Get
Set(ByVal Value As String)
_descript = Value
End Set
End Property
End Class
Alternatively, yes you can extend any object and add whatever you like.
Public Class SpecialTreeView
Inherits System.Windows.Forms.TreeN
Dim _descript As String
Dim _id As String
Public Property ID() As String
Get
Return _id
End Get
Set(ByVal Value As String)
_id = Value
End Set
End Property
Public Property Descript() As String
Get
Return _descript
End Get
Set(ByVal Value As String)
_descript = Value
End Set
End Property
End Class
Well eekj
I think he wants a Description property for each node of the treeview
Not for the TreeView itself
I think he wants a Description property for each node of the treeview
Not for the TreeView itself
Whoops, thats a typo... heh. Oh well.
Public Class SpecialTreeNode ' -- not treeview
Inherits System.Windows.Forms.TreeN ode
Public Class SpecialTreeNode ' -- not treeview
Inherits System.Windows.Forms.TreeN
ASKER
eekj:
In your first comment, you say that it would get messy.. do you mean that I really shouldn't add properties to the treeview and use the TAG? Or should I use the code to add properties that you described?
If I'd better use the tag, how could I handle the format then?
arif_eqbal: What do you think?
Thanks,
MA
In your first comment, you say that it would get messy.. do you mean that I really shouldn't add properties to the treeview and use the TAG? Or should I use the code to add properties that you described?
If I'd better use the tag, how could I handle the format then?
arif_eqbal: What do you think?
Thanks,
MA
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you can use the tag its better, go for new property if tag is already used for something else...
ASKER
Thank you very much guys for your help. the numbering function works like a charm and the property stuff is really useful to me.
MA
MA