循环访问 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);
       }
    }

     

你可能感兴趣的:(循环访问 TreeView 控件的所有节点)