Answered by:
get a list of treeview selected node children

Question
-
User-867857476 posted
Hi, i want get a list or array of values of treeview selected node all children in each level.
for example: if i select programming node > string[] nodes = new string[] {"programming", "web", "asp.net","php","application","c#","Java"};
-network
-programing
--web
---asp.net
---php
--application
---c#
---Java
Friday, October 18, 2013 12:40 PM
Answers
-
User2047328858 posted
Hi Mostafa,
Here is the recursive method, I hope this will helpful for you.
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { List<string> lstProgramming = new List<string>(); for (int intIndex = 0; intIndex < TreeView1.SelectedNode.ChildNodes.Count; intIndex++) { lstProgramming.Add(TreeView1.SelectedNode.ChildNodes[intIndex].Text); RecursiveCall(TreeView1.SelectedNode.ChildNodes[intIndex], ref lstProgramming); } } private void RecursiveCall(TreeNode treeNode, ref List<string> lstProgramming) { // Print each node recursively. for (int intIndex = 0; intIndex < treeNode.ChildNodes.Count; intIndex++) { lstProgramming.Add(treeNode.ChildNodes[intIndex].Text); } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, October 19, 2013 2:27 PM
All replies
-
User2047328858 posted
Hi,
you can get the list of child node using the below code
List<string> lstProgramming = new List<string>(); for (int intIndex = 0; intIndex < TreeView1.SelectedNode.ChildNodes.Count; intIndex++) { lstProgramming.Add(TreeView1.SelectedNode.ChildNodes[intIndex].Text); }
Friday, October 18, 2013 1:09 PM -
User-867857476 posted
Thanks a lot,
It's work but in this code if i select Programming it's return first level childs (Web,Application), but i want return all level childs (Web,asp,php,application,c#,Java,...)
somthing like <cite>Recursivity Function</cite>s
Friday, October 18, 2013 4:35 PM -
User2047328858 posted
Hi Mostafa,
Here is the recursive method, I hope this will helpful for you.
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { List<string> lstProgramming = new List<string>(); for (int intIndex = 0; intIndex < TreeView1.SelectedNode.ChildNodes.Count; intIndex++) { lstProgramming.Add(TreeView1.SelectedNode.ChildNodes[intIndex].Text); RecursiveCall(TreeView1.SelectedNode.ChildNodes[intIndex], ref lstProgramming); } } private void RecursiveCall(TreeNode treeNode, ref List<string> lstProgramming) { // Print each node recursively. for (int intIndex = 0; intIndex < treeNode.ChildNodes.Count; intIndex++) { lstProgramming.Add(treeNode.ChildNodes[intIndex].Text); } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, October 19, 2013 2:27 PM -
User-867857476 posted
Hi jsampath,
Thanks for your solution,
visit this threads and help me please
http://forums.asp.net/p/1944556/5539656.aspx?p=True&t=635176939339485134&pagenum=1
http://forums.asp.net/p/1943823/5536699.aspx?p=True&t=635174316718654067&pagenum=1
Saturday, October 19, 2013 3:34 PM