combobox get file lists

G

Guest

My code returns the list of files in the directory I desire, but it displays
the entire path to the file and the file name. I can msgbox the desired
result (just the file name), but I believe the readonlycollection has
something to do with this...

Dim numofchars As Integer = (memberpath & "\" &
Me.EmpMemberNoTextBox.Text).ToString.Length + 1
Dim filelist As
System.Collections.ObjectModel.ReadOnlyCollection(Of String)
filelist = My.Computer.FileSystem.GetFiles(memberpath & "\"
& Me.EmpMemberNoTextBox.Text, FileIO.SearchOption.SearchTopLevelOnly)
For Each foundfile As String In filelist
Dim lengthofpath As Integer = (foundfile).Length.ToString
Dim filenamelength As Integer = lengthofpath - numofchars
Dim filename As String =
Microsoft.VisualBasic.Right(foundfile, filenamelength)
Me.ComboBxMemberFiles.Items.Add(filename.ToString)
Next

How can I display just the filename in the combo box?

Thank you!
 
G

Guest

Could you provide me an example of how to populate the combobox with only
filenames and NOT the entire path w/ filenames? Thank you again.
 
G

Guest

I found a solution to this - in case anybody else is needing to do the same:

Dim files As String() = Directory.GetFiles(memberpath &
"\" & Me.EmpMemberNoTextBox.Text)

For Each file As String In files
ComboBxGetFiles.Items.Add(Path.GetFileName(file))
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top