在treeview c#中列出主文件夹中的子文件夹和文件 [英] Listing subfolders and files from an main folder within treeview c#

查看:63
本文介绍了在treeview c#中列出主文件夹中的子文件夹和文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..


我正在填写form1中的树视图,该视图基于checkedlistbox中的checkitems,该文件位于form2中但无法列出已检查文件夹的子文件夹和文件。


有谁能请帮帮我????


谢谢..


嗨。 。


这是我的方案,但没有收到任何错误..


我有两种形式form1和form2,在form1我有一个treeview和form2我有checklistbox,我填写如下: -

展开 | 选择 | Wrap < span class =codeDivider> | 行号 解决方案

你能显示发生错误的代码吗?


以下是我的代码,我的GetDirectories收到错误。 。


无法找到路径'E:\ mails \ System.Windows.Forms.CheckedListBox + Chec kedItemCollection''的一部分。




private void ListDirectory(TreeView treeView,string path)

{

treeView.Nodes.Clear();

var rootDirectoryInfo = new DirectoryInfo(path);

treeView.Nodes.Add(CreateDirectoryNode(rootDirecto ryInfo));

}


私有静态TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)

{

var directoryNode = new TreeNode(directoryInfo.Name);

foreach(directoryInfo.GetDirectories()中的var目录)

directoryNode.Nodes.Ad d(CreateDirectoryNode(direct ory));

foreach(directoryInfo.GetFiles()中的var文件)

directoryNode.Nodes.Add(new TreeNode(file.Name)) ;

返回directoryNode;

}


请帮助我......


...............................

Hi..

I am populating a treeview in form1 based on the checkeditems in checkedlistbox which is in form2 but am unable to list the subfolders and files of the checked folder..

Can anyone please help me????

Thanks..

hi..

This is my scenario but am not getting any error..

I have two forms form1 and form2,in form1 i have an treeview and in form2 i have checkedlistbox which i am populating as follows:-

Expand|Select|Wrap|Line Numbers

解决方案

hi, can u show the code where the error occurs?


Following is my code and am getting error for GetDirectories..

Could not find a part of the path ''E:\mails\System.Windows.Forms.CheckedListBox+Chec kedItemCollection''.



private void ListDirectory(TreeView treeView, string path)
{
treeView.Nodes.Clear();
var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Nodes.Add(CreateDirectoryNode(rootDirecto ryInfo));
}

private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
{
var directoryNode = new TreeNode(directoryInfo.Name);
foreach (var directory in directoryInfo.GetDirectories())
directoryNode.Nodes.Add(CreateDirectoryNode(direct ory));
foreach (var file in directoryInfo.GetFiles())
directoryNode.Nodes.Add(new TreeNode(file.Name));
return directoryNode;
}

Please help me...


...............................


这篇关于在treeview c#中列出主文件夹中的子文件夹和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆