用C#实现 如何获取选中treeview节点,将其节点中文件夹下文件列表绑定到listview 类中

2024-12-19 12:04:26
推荐回答(2个)
回答1:

///


/// 初始化树
///

public void InitTree()
{
TreeNode root = new TreeNode("所有磁盘");
DriveInfo[] drives = DriveInfo.GetDrives(); //获取计算上的逻辑驱动器
//循环将所有磁盘添加到根节点
for (int i = 0; i < drives.Length; i++)
{
TreeNode drive = new TreeNode(drives[i].ToString());

root.Nodes.Add(drive);
drive.Tag = drive.Text;
drive.Text = drive.Text.Substring(0, 2);
GetFiles(drive);
}
this.treeView1.Nodes.Add(root); //将根节点添加到树中
}

回答2:

没分:--(