zoukankan      html  css  js  c++  java
  • 小型资源管理器之动态添加TreeView节点

    FrmMain主界面

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.IO;
     7 using System.Linq;
     8 using System.Text;
     9 using System.Threading.Tasks;
    10 using System.Windows.Forms;
    11 
    12 namespace Day09_0300小型资源管理器
    13 {
    14     public partial class Form1 : Form
    15     {
    16         public Form1()
    17         {
    18             InitializeComponent();
    19         }
    20         public void BindInfo(TreeNode node) 
    21         {
    22             lvMain.Items.Clear();
    23             //绑定子目录
    24             DirectoryInfo dic = new DirectoryInfo(node.Tag.ToString());
    25             DirectoryInfo[] dirs = dic.GetDirectories();
    26             foreach (DirectoryInfo item in dirs)
    27                 {
    28                TreeNode tn=new TreeNode();
    29                 tn.Text=item.Name;
    30                 tn.Tag=item.FullName;
    31                 node.Nodes.Add(tn);
    32                   }
    33             FileInfo[] file = dic.GetFiles();
    34             ListViewItem lvi = new ListViewItem();
    35             foreach (FileInfo di in file)
    36             {
    37                 lvi = new ListViewItem(di.Name);
    38                 lvi.SubItems.Add(di.FullName);
    39                 lvi.SubItems.Add(di.Extension);
    40                 lvi.SubItems.Add(di.Length.ToString());
    41                 lvMain.Items.Add(lvi);
    42             }
    43 
    44         }
    45        
    46         private void tvList_AfterSelect(object sender, TreeViewEventArgs e)
    47         {
    48             TreeNode node = this.tvList.SelectedNode;
    49             this.BindInfo(node);
    50         }
    51 
    52     }
    53 }
  • 相关阅读:
    c++类的知识点(1)
    并查集经典例题分析
    并查集
    bfs-迷宫
    出栈次序--数学归纳法--蓝桥
    九宫重排
    Tomcat详解
    寒假日记-第三天
    寒假日记-第二天(MySQL语句)
    Java学期总结
  • 原文地址:https://www.cnblogs.com/liutao1122/p/7138359.html
Copyright © 2011-2022 走看看