Ok here is my question:
f.ex I have data structure something like this:
String name
- List<String> subNames;
- List<String> subSubNames;
I can easily popul开发者_Go百科ate tree view with the data. But how I should get vise versa stuff on this.
for example: I select some subSubName in the treeview, what is the easiest way to get Name, but not in the treeview it self but my own object.
I can code it by myself, but maybe there is an easiest way of doing that? Something like bind object to the treeview etc...
You can use the Tag
property of TreeNode
to store data about the node.
An example where variable name
contains your data and treeView1
is your TreeView:
TreeNode node = new TreeNode();
node.Text = name.ToString(); //can be any string
node.Tag = name;
treeView1.Nodes.Add(node);
To retrieve the data from a node, just cast the Tag
to the right class:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
name = (Name)e.Node.Tag;
}
精彩评论