Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying folder contents in a listbox

Status
Not open for further replies.

nondrinker

Programmer
Jan 23, 2002
53
US
Hello,

I have been trying to display the contents of a folder in a list box but so far i am having some problems. The closest i have come to is display the file name in a multiline textbox using this code.
***********************************
Dim varFolderPath As String
varFolderPath = "\\[My folder path here]"

Dim objFile As FileInfo
Dim objDir As DirectoryInfo
Dim t As String
t = ""

For Each objFile In objDir.GetFiles("*.*")

Try

txtFiles.Text = objFile.Name.ToString
If t <> "" Then
t = t & ";"

End If
t = objFile.Name.ToString
txtFiles.Text = t
Catch ex As Exception
MsgBox("Error in displaying files")
End Try

Next

************************************
But what this code does is just display the name of the last file in the folder instead of all the files. But eventually i would like to use a listbox, instead of a text box to display the names of all files in the folder.
I am using MS VisualStudio .NET 2003.

Any help will be appreciated.
Thanu you.
 
txtFiles.Text = t
The line above means that the Text property is reset on each loop. Try using &= instead of just =.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thank you for your time.
Instead of using the multiline text box, i changed it to a listbox (named lstbox) and adding this line of code did the trick: lstBox.Items.Add(t)
 
VS 2005 has a filelistbox .. don't know if VS2003 too having it.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top