I have a treeview. The user should select one o its node (a folder) and I need to read its path, because the user will send a file to be stored in this folder.
How do I read the selected node of a treeview?
TIA
Moisés
Marked as answer by Moises Durovni on Jan 05, 2013 09:08 PM
With SelectedValue property, you can read the current selected value. With the SelectedNode property can give you an easy access to Text, Value and ValuePath of the selected node. This last property (ValuePath) is an "union" of all path. For example, with
this treeview structure
A
1A
2A
B
1B
if you select "2A", ValuePath will be "A/2A". Note you can set PathSeparator (default is '/') as you prefer.
Please, "Mark As Resolved" if my reply was helpful to you
--
Blog
Moises Durov...
Member
29 Points
79 Posts
treeview - how to get the selected node
Jan 05, 2013 01:16 PM|LINK
Hi folks,
I have a treeview. The user should select one o its node (a folder) and I need to read its path, because the user will send a file to be stored in this folder.
How do I read the selected node of a treeview?
Moisés
andri745
Member
163 Points
73 Posts
Re: treeview - how to get the selected node
Jan 05, 2013 08:10 PM|LINK
It's very simple. You can use the SelectedNodeChanged event of TreeView:
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { string valNode = TreeView1.SelectedValue; TreeNode tn = TreeView1.SelectedNode; }With SelectedValue property, you can read the current selected value. With the SelectedNode property can give you an easy access to Text, Value and ValuePath of the selected node. This last property (ValuePath) is an "union" of all path. For example, with this treeview structure
if you select "2A", ValuePath will be "A/2A". Note you can set PathSeparator (default is '/') as you prefer.
--
Blog
Microsoft MCPD - Web Developer .NET 4
Moises Durov...
Member
29 Points
79 Posts
Re: treeview - how to get the selected node
Jan 05, 2013 09:08 PM|LINK
Thanks for your help!!!
Regards
Moises Durovni
Moisés