未在ListView中显示的所有子目录 [英] All sub-drectories not shown in ListView

查看:81
本文介绍了未在ListView中显示的所有子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览目录,并希望在列表视图中显示子目录.令人惊讶的是,我只能看到其中一些目录,而其他目录未显示.我尝试调试它,它会扫描所有子目录,但不会显示全部.您能帮我解决问题吗?我想我在使用listview时做错了.

这是我的代码.

I''m scanning through a directory and want to display the sub-directories in list view. Surprisingly I can only see some of the directories, others are not shown. I tried debugging it and it scans through all sub-directories, but just don''t display all. Could you help me figure out the problem? I guess I''m doing something wrong with the use of listview.

Here is my code.

foreach (DirectoryInfo di in dir.GetDirectories())
{
   ListViewItem item = new ListViewItem();
   item.ImageIndex = 0;
   item.Text = di.Name;
   item.Tag = di.FullName;
   listView_Files.Items.Add(item);
}



谢谢.



Thanks.

推荐答案

您尝试对GetDirectories()使用SearchOptions参数吗?

Did you try using the SearchOptions parameter for GetDirectories()?

DirectoryInfo dir = new DirectoryInfo("");
foreach (DirectoryInfo di in dir.GetDirectories("*.*", SearchOption.AllDirectories)
{
}


DirectoryInfo di = new DirectoryInfo(@"C:\Windows");
DirectoryInfo[] _allDirectories = di.GetDirectori("*.*",SearchOption.AllDirectories)
foreach (var item in _allDirectories)
{
   ListViewItem item = new ListViewItem();
   item.ImageIndex = 0;
   item.Text = di.Name;
   item.Tag = di.FullName;
   listView_Files.Items.Add(item);
}


我尝试了上述选项,但没有帮助.我只想显示顶层目录.我还尝试使用下面的方法也无法解决问题.

DirectoryInfo [] _allDirectories = dir.GetDirectories("*.*",SearchOption.TopDirectoryOnly);

我无法弄清楚为什么某些目录被跳过了.列表视图使用任何索引设置吗?我看不到被跳过的目录的属性与显示的属性没有区别:(
I tried the above options but didn''t help. I wanted to display the directories of the top level only. I also tried using the below which didn''t solve either.

DirectoryInfo[] _allDirectories = dir.GetDirectories("*.*", SearchOption.TopDirectoryOnly);

I am not able to figure out why some of the directories are skipped. Are there any diectory settings used by the listview? I see no difference in properties of directory which are skipped and the ones shown :(


这篇关于未在ListView中显示的所有子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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