本文介绍了如何跟踪Treeview控件的所有TreeNodes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不同级别的treeView。 Parent-Child-SubNodes

I'm having a treeView with in different levels. Parent-Child-SubNodes

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.

推荐答案

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

CallRecursive(Misc_Treeview);



参考: []


这篇关于如何跟踪Treeview控件的所有TreeNodes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 21:20