循环访问 TreeView 控件的所有节点

  1. 创建测试每个节点的递归过程 .  

  2. private void PrintRecursive(TreeNode treeNode)
    {
       // Print the node.
       System.Diagnostics.Debug.WriteLine(treeNode.Text);
       MessageBox.Show(treeNode.Text);
       // Print each node recursively.
       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);
       }
    }

     

posted @ 2016-03-22 11:08  镹丶天  阅读(188)  评论(0编辑  收藏  举报

Throw new Exception("object not found");