TreeNode design is wrong

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why TreeNode is a string? It should hold a Object and get label from
Object.ToString(). Then much better. Easy to trace all objects in a TreeView.
 
How would that work exactly? A TreeView control is often used to simply
display strings, without a backing object.

Even when an object is used, what if it's not your class, so you didn't get
a say in what is returned by ToString? If it is your class, do you really
want to change the ToString method just so it can have a value that can be
used in a specific control? What if ToString conatins more information than
you'd like in your UI? Or less? What if you want to have the TreeNode text
vary depending on something else going on in your app?

If this is something that will help you, you should override TreeNode to
automatically set the Text property to be equal to the string returned by
tag.ToString. As a design for the base TreeNode, however, it would be
extremely limiting.
 
Why TreeNode is a string?

? TreeNode is an object.
It should hold a Object and get label from
Object.ToString(). Then much better. Easy to trace all objects in a
TreeView.

You can derive your own node from TreeNode. IIRC, you can also store an
object for each node in the Tag property.
 
Back
Top