473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

combobox get file lists

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!
May 12 '06 #1
4 1279
Uses FileInfo class to help you to get filename from a full path.

Tedmond

"mafandon" wrote:
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!

May 13 '06 #2
Mafandon,

I use the Path Class to get parts of paths.

http://msdn2.microsoft.com/en-us/lib...m.io.path.aspx

I hope this helps,

Cor

"mafandon" <ma******@discussions.microsoft.com> schreef in bericht
news:DF**********************************@microsof t.com...
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!

May 13 '06 #3
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.

"Cor Ligthert [MVP]" wrote:
Mafandon,

I use the Path Class to get parts of paths.

http://msdn2.microsoft.com/en-us/lib...m.io.path.aspx

I hope this helps,

Cor

"mafandon" <ma******@discussions.microsoft.com> schreef in bericht
news:DF**********************************@microsof t.com...
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!


May 16 '06 #4
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
"mafandon" wrote:
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.

"Cor Ligthert [MVP]" wrote:
Mafandon,

I use the Path Class to get parts of paths.

http://msdn2.microsoft.com/en-us/lib...m.io.path.aspx

I hope this helps,

Cor

"mafandon" <ma******@discussions.microsoft.com> schreef in bericht
news:DF**********************************@microsof t.com...
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!


May 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mr. B | last post by:
I've been seeking the solution to this. But can't figure it out (sounds simple enough). When you Populat a ComboBox, you can select the initial displayed items on startup simply by setting the...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
4
by: WhiteWizard | last post by:
Alright everyone, I've managed to stump this group 2 or 3 times now. Don't let me down on this one ;) I have a combo box that lists a number of tests to be run. The user would like the option...
0
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number...
10
by: Doug Bell | last post by:
Hi I am still having problems with Tabbing through a DataGrid with a DataGridComboBox Column. I need to allow the User to Type the value into the ComboBox so consequently its ComboBoxStyle is...
2
by: mnms | last post by:
Hi, I'm wondering if it's possible "manually" add an extra value to a combobox list. At the moment I have two fields, one "transparent" is a checkbox that lets you define a colour as...
0
by: Maninder Karir | last post by:
Hi, I have defined some lists in excel (using ctrl + F3). How can i recall these lists to a combobox? Thanks
3
by: Marc Gravell | last post by:
Sure; just set the DataSource, DisplayMember and ValueMember of a DataGridViewComboBoxColumn (below ). Marc using System.Collections.Generic; using System.Windows.Forms; using...
4
by: yaaara | last post by:
Hi, Here's another problem that I came up with: I have a combobox in a form with 2 columns. What I need is the following: 1. The combobox to be cleared on form_load (not only the text, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.