Filenames in a listbox (From a newbee)

Decklan

Member
Joined
Feb 3, 2006
Messages
13
Programming Experience
Beginner
Hello

I’ve just started learning VB.Net and I’m trying to write my first program.

The program is to organize customer names, address, products and stuff. I’m sure that a database would be easier, but I would like to use text files to store the information. The program creates a new text file for every customer.

This is my question….
Could someone please tell me or show me how to display a list of text file filenames in a list box?

Many Thanks

Decklan
 
VB.NET:
Dim folderpath As New IO.DirectoryInfo("C:\Customers")
ListBox1.DataSource = folderpath.GetFiles("*.txt")
 
i am working on a similar problem. I am trying to show file names in a list box, but i keep getting the whole path. I sent a friend the code, and some files i wanted to appear in the box, but he couldn't get the list box to work at all. He told me I need generic paths, I am lost. I also just started learning VB.

The code, which I found somewhere else, thats works on my computer is:
VB.NET:
Private Sub FillListBox()
'Fill list box with list of bitmap files in the Windows directory
Me.Listbox1.DataSource = System.IO.Directory.GetFiles("D:\VB Projects\My Stuff\", "*.jpg")
Me.lbSecElePro.DataSource = System.IO.Directory.GetFiles("D:\VB Projects\My Stuff\", "*.jpg")
End Sub
Like I said I can get it on my computer, but it shows the whole path, I would like only the file name, and for it to work somewhere other then my computer of course. Please help.
 
Last edited by a moderator:
You can use my example and set Listbox.ValueMember to "Name" property of FileInfo.
VB.NET:
Dim folderpath As New IO.DirectoryInfo("C:\Customers")
ListBox1.DataSource = folderpath.GetFiles("*.txt")
ListBox1.ValueMember = "Name"
 
Back
Top