本文介绍了未在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.

推荐答案

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);
}



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

11-02 04:36