zoukankan      html  css  js  c++  java
  • treeView把文件夹作为根节点内容作为子节点

     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                TreeNode root = new TreeNode();   
               root.Text = "目录";   
               GetFiles(@"E:Tools", root);   
               treeView1.Nodes.Add(root); 
    
            }
    
          private void GetFiles(string filePath, TreeNode node)   
           {   
               DirectoryInfo folder = new DirectoryInfo(filePath);   
               node.Text = folder.Name;   
               node.Tag = folder.FullName;   
                  
               FileInfo[] chldFiles = folder.GetFiles("*.*");   
               foreach (FileInfo chlFile in chldFiles)   
               {   
                   TreeNode chldNode = new TreeNode();   
                   chldNode.Text = chlFile.Name;   
                   chldNode.Tag = chlFile.FullName;   
                   node.Nodes.Add(chldNode);   
               }   
      
               DirectoryInfo[] chldFolders = folder.GetDirectories();   
               foreach (DirectoryInfo chldFolder in chldFolders)   
               {   
                   TreeNode chldNode = new TreeNode();   
                   chldNode.Text = folder.Name;   
                   chldNode.Tag = folder.FullName;   
                   node.Nodes.Add(chldNode);   
                   GetFiles(chldFolder.FullName, chldNode);   
               }   
                  
           }
    
        }
    三思而又行。
  • 相关阅读:
    Java 日期 Api
    Java 基础-反射
    Java 基础-运算符
    Android findBugs
    java-基础练习题3
    java-基础练习题2
    java-基础练习题1
    java-基础练习题
    Java IO 遇到的错误
    Android测试框架-uiautomator
  • 原文地址:https://www.cnblogs.com/jun-jie/p/3569591.html
Copyright © 2011-2022 走看看