zoukankan      html  css  js  c++  java
  • 将文件夹层次显示在treeview控件中

    private void Form1_Load(object sender, EventArgs e)
            {
                string rootpath = @"E:\config";
                DirectoryInfo dir = new DirectoryInfo(rootpath);
                TreeNode rootnode = new TreeNode();
                rootnode.Text = "任务列表";
                treeView1.Nodes.Add(rootnode);
    
                Recursion(dir, rootnode);
            }
    
            private void Recursion(DirectoryInfo dirParent, TreeNode tnParent)
            {
                DirectoryInfo[] dirarr = dirParent.GetDirectories();
                if (dirarr == null) return;//若无子文件夹则退出
                foreach (DirectoryInfo diri in dirarr)
                {
                    TreeNode siteNode = new TreeNode();
                    siteNode.Text = diri.Name;
                    siteNode.Name = diri.FullName;
                    tnParent.Nodes.Add(siteNode);
    
                    Recursion(diri, siteNode);//递归
                }
            }
        }
  • 相关阅读:
    java lambda
    ssh配置基础
    信息安全课程笔记1
    字体标记与文字布局
    字符串:格式化
    字符串
    标签详细描述
    HTML中的标签列表
    html(1)
    python列表命令
  • 原文地址:https://www.cnblogs.com/i80386/p/2332580.html
Copyright © 2011-2022 走看看