使用根文件夹路径中的文件/文件夹填充列表框 [英] Populating a listbox with files / folders from a root folder path

查看:67
本文介绍了使用根文件夹路径中的文件/文件夹填充列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我一直致力于个人项目,每个职位都有一个项目文件夹。目前,该项目文件夹位置设置为数据库中的路径。路径是E:\Projects \ClientName

I have been working on a personal project that has a project folder per job. currently, that project folder location is set as a path in the Database. The path is E:\Projects\ClientName

从那里,我试图使它,以便当我从列表中选择客户端时,该客户端的文件夹(客户端名称)也选中了保存在数据库中的文件夹,该文件夹的文件夹显示在树视图中(在根客户端文件夹下)。
如果我单击树视图中的文件夹,则内容将显示在右侧的列表框中。只有所选文件夹的文件显示在右侧的列表框中,只显示文件夹和文件夹。子文件夹显示在左侧的树视图中。

from there, i am trying to make it so that when i select the Client from a list, the folder for that client (clients name is also saved in the Database) is selected and the folders of that folder are displayed in a Treeview (under the root Client folder). If i click a folder in the treeview, the contents are shown in a listbox on the right. Only the files of a selected folder are shown in the listbox on the right and only the folders & subfolders are shown in the treeview on the left.

在System.IO上找到了一些主题,但没有任何与我想要实现的相似的内容。

Did find a few topics on System.IO but nothing that i would be similar to what i am trying to achieve.

有没有人有任何我可以参考的好链接?

Does anyone have any good links that i can be referred to?

像这样的东西

此外,我相信我可以过滤列表框但它只需要显示某些文件类型和图标:

Also, im sure i could filter the listbox but it only needs to show certain filetypes and the icons:

.IDW

.IPT

.IAM

.XLS

.PDF

.JPG

.DWG

.DXF

注意:我可以使用DevExpress工具包显示图标我已经足够了

NOTE: I can displays the icons using the DevExpress toolkit i have easily enough

感谢任何帮助

Nacho

纳乔是奈杰尔的衍生物 - 真实的事实!我是VB.Net的自学者。 50%的时间,我百分之百正确!

Nacho is the derivative of Nigel - True fact! I am self taught in VB.Net. 50% of the time, I am right 100% of the time!

推荐答案

您好

这里有一些代码来显示ListBox中的过滤文件列表。

Here is some code to show filtered file list in a ListBox.

' Form1 with ListBox1
Option Strict On
Option Explicit On
Public Class Form1
  Dim path As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\New folder"
  Dim filters As List(Of String) = {"*.idw", "*.ipt", "*.iam", "*.xls", "*.pdf", "*.jpg", "*.dwg", "*.dxf"}.ToList
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ListBox1.DataSource = GetFiles(path)
  End Sub
  Function GetFiles(p As String) As List(Of String)
    Dim so As IO.SearchOption = IO.SearchOption.AllDirectories
    Dim results As New List(Of String)
    For Each filter As String In filters
      results.AddRange(IO.Directory.GetFiles(p, filter, IO.SearchOption.AllDirectories))
    Next
    Return results
  End Function
End Class


这篇关于使用根文件夹路径中的文件/文件夹填充列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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