循环访问 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控件的Node节点延迟加载


下一篇:基于Treeview控件遍历本地磁盘