Click here to Skip to main content
15,888,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having a treeView with in different levels. Parent-Child-SubNodes
XML
Here I want to trace all the TreeNodes  of a Treeview Control. Please help me out. I've a req like i need to make Visible false for some sub nodes of the Treeview as per user Rights.

Calling A function from Page_Load()
ListNodes(Misc_Treeview);


<pre lang="cs">
private void ListNodes(TreeView TreeView1)
{
  foreach (TreeNode nodes in TreeView1.Nodes)
  {
     //int count = 0;
     var V = nodes.ChildNodes;

     foreach (var item in V)
     {

      //count++;
     }


   }
}
</pre>



Thanks in advance.
Posted

1 solution

C#
private void PrintRecursive(TreeNode treeNode)
{
   //do something with each node
   //System.Diagnostics.Debug.WriteLine(treeNode.Text);
   foreach (TreeNode tn in treeNode.Nodes)
   {
      PrintRecursive(tn);
   }
}

// Call the procedure using the TreeView.
private void CallRecursive(TreeView treeView)
{
   // Print each node recursively.
   TreeNodeCollection nodes = treeView.Nodes;
   foreach (TreeNode n in nodes)
   {
      PrintRecursive(n);
   }
}

call the recursive method as below
C#
CallRecursive(Misc_Treeview);

refer : How to: Iterate Through All Nodes of a Windows Forms TreeView Control[^]
 
Share this answer
 
v3
Comments
Maciej Los 18-Aug-15 6:25am    
5ed!

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