Is it possible to add text, and a value, to a tree node?
For example, a node may have the text Desktop
, but the value is C:\Documents and Settings\All Users\Desktop
.
Is it possible to add text, and a value, to a tree node?
For example, a node may have the text Desktop
, but the value is C:\Documents and Settings\All Users\Desktop
.
A TreeNode has a Tag property. You can set that to any object you like and can use as your underlying value, while the normal text of the node is displayed in the tree.
E.g.
TreeNode node = new TreeNode("Desktop") { Tag = "C:\Documents and Settings\All Users\Desktop" };
You may to use Tag property for storing values:
TreeNode node = new Node();
node.Tag = "value";
Advantage is that you can assign to Tag any object you want not just integer or string value.
Then you can use Tag as follow:
var value = node.Tag as YourObjectType;