Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI.

I have the value path and i want to show the treeview from root to last node of the valuepath (195/231/301/404/561)

561 is the last one.

How could i do this?
Posted

1 solution

if you use WinForms, you can populate tree view with values assinging them unique keyes.
e.g.
C#
var root = treeViewDemo.Nodes.Add("195", "root");
var c = root.Nodes.Add("231", "text 231");
var d = c.Nodes.Add("301", "text 301");
var e = d.Nodes.Add("404", "text 404");
var f = e.Nodes.Add("561", "text 561");
// other nodes are added here
// treeView is collapsed


then use this code to navigate to requested node by node's key taken from value path
C#
var node = treeViewDemo.Nodes.Find("561", true)[0];
treeViewDemo.SelectedNode = node;
// treeView is expanded to the selected node
 
Share this answer
 
v2
Comments
BillWoodruff 20-Mar-14 14:24pm    
+5 A very good answer. Note that, unfortunately, the MS TreeView allows any number of Nodes to have the same Key, and Text (Value).

The 'Fullpath property of a TreeNode returns the concatenation of the ancestor's Text (Value) separated by the specified 'PathSeparator property string. So, unless the text of the Key appears in the Text property of a TreeNode, looking at the 'FullPath will not help you know what Key to search for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900