如何循环遍历 ListView 的特定子项?

发布于 2024-10-15 08:20:43 字数 761 浏览 2 评论 0原文

我正在制作一个程序,它使用 ListView 来查看所选目录中的目录和文件。 ListView 本身有两列,并设置为详细信息视图。两列是文件夹名称(通过按钮选择的目录)和电影名称(将在 ListView 上列出所选目录中的所有电影)。

我希望 ListView 做的是在将文件夹添加到 ListView 后,子项目应该隐藏,直到单击左侧列(选定的目录)。

我试图循环遍历 ListView 的子项,但问题是它不仅打印出目录中的所有文件和文件夹,而且还循环遍历并打印出目录名称。

对于那些想查看代码和项目的人,我在下面提供了下载链接。

http://www8.zippyshare.com/v/75161785/file.html

这里也是我的代码的一部分,用于显示目录中的文件和文件夹数组,正如您所看到的,我的问题是它也循环遍历我的项目,我希望它只显示一次。

        for (int i = 0; i < jointArray.Length; i++)
        {
                ListViewItem item = new ListViewItem(fi.Name);
                item.SubItems.Add(jointArray[i]);
                listView1.Items.Add(item);
        }

I'm making a program that uses a ListView to view the directories and files in the selected directory. The ListView itself has two columns and is set to Details view. The two columns are Folder Name (the directory selected from a button) and Movie Names (which will list all movies in the selected directory on the ListView).

What I would like the ListView to do is after the folder has been added to the ListView the subitems should be hidden until the left-hand column (selected directory) is clicked.

I have attempted to loop through the subitems of a ListView, but the problem is that not only does it print out all the files and folders within the directory, it also loops through and prints out the directory name as well.

For those that would like to see the code and project I have provided a Download link below.

http://www8.zippyshare.com/v/75161785/file.html

Also here is part of my code to display the array of files and folders within a directory, as you can see my problem is that it also loops through my item which i would like it to display only once.

        for (int i = 0; i < jointArray.Length; i++)
        {
                ListViewItem item = new ListViewItem(fi.Name);
                item.SubItems.Add(jointArray[i]);
                listView1.Items.Add(item);
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2024-10-22 08:20:43

看起来您需要一个 TreeControl,每个目录都会折叠起来,直到您单击它为止(很像 Windows 资源管理器)。

然后您可以递归地查看所有文件夹和文件夹。文件并将它们添加到树视图中。

Looks like you need a TreeControl with each directory collapsed until you click it (much like windows explorer).

Then you can recursively look through all your folders & files and add them to the treeview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文