How can I populate a listbox with all the files in a listbox?
Printable View
How can I populate a listbox with all the files in a listbox?
VB Code:
' make a reference to a directory Dim di As New DirectoryInfo("c:\") Dim diArr As DirectoryInfo() = di.GetDirectories() Dim diar1 As FileInfo() = di.GetFiles() ' list the names of all the subdirectories in the specified directory Dim dri As DirectoryInfo 'BeginUpdate method freezes painting while you add items ListBox1.BeginUpdate() For Each dri In diArr ListBox1.Items.Add(dri) Next 'EndUpdate resumes painting of listbox ListBox1.EndUpdate() 'list the names of all files in the specified directory Dim dra As FileInfo For Each dra In diar1 listbox2.items.add(dra) Next
lol... i just found this stuff I had filed away in my 'common code snippets'
VB Code:
[b]'Adding Files in a directory to a listbox[/b] ListBox1.DataSource = Directory.GetFiles("C:\") [b]'Adding subdirectories of a directory to a listbox[/b] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim r As String() r = Directory.GetDirectories("C:\") ListBox1.DataSource = r End Sub
Why not include them in the VBCodeBook.NET program to help other users? If you wish to send them, i'll include them in a future release.Quote:
lol... i just found this stuff I had filed away in my 'common code snippets'
:D
Well, consider it submitted :)
Thanks :cool: