|
-
Jan 11th, 2008, 11:58 AM
#1
Thread Starter
New Member
[RESOLVED] VB simple query (I think)
Hello all, I'm just new on here and I thought that some of you guys might be able to help me out with something thats been confusing me for a while now...
Ok basically I'm using VB.net to create a program and part of it's functionality requires a combo box to be populated by titles of files from a directory on my hard drive. That bit has been done using this :
Me.cbo_user.DataSource = New System.IO.DirectoryInfo("E:\Pics\").GetFiles("*.jpg")
All works fine, combo box is successfully populated but the thing I'm struggling with is finding out how to remove the .jpg file extension from every item that is added to the combo box. I have been able to remove the extension using :
Me.cbo_user.Text = cbo_user.Text.Substring(0, cbo_user.Text.Length - 4)
Problem with this is, obviously it only removes the extension from the currently selected item, whereas I want the entire list "extension free"
Any help would be much appreciated, cheers.
Robin
-
Jan 11th, 2008, 12:19 PM
#2
Re: VB simple query (I think)
Load the list into an array (or a List(Of String) ) .... loop through it removing the extension, and then bind that to the combo....
-tg
-
Jan 11th, 2008, 12:21 PM
#3
Thread Starter
New Member
Re: VB simple query (I think)
Yeah that was another way I tried but I'm relatively new to VB.net and I'm a bit unsure on working with arrays etc. I take it thats the best way then? I'll give it another shot sure. Cheers.
-
Jan 11th, 2008, 12:22 PM
#4
Re: VB simple query (I think)
perhaps something like this would help:
Code:
Dim Files() As String = System.IO.Directory.GetFiles("E:\Pics\", "*.jpg")
For Counter As Integer = 0 To Files.GetUpperBound(0)
Files(Counter) = Files(Counter).Remove(Files(Counter).Length - 4, 4)
Next Counter
Me.cbo_user.DataSource = Files
-
Jan 11th, 2008, 12:30 PM
#5
Thread Starter
New Member
Re: VB simple query (I think)
Thats exactly what I was looking for thanks a lot! Only thing is, using that code leaves me with the entire path name before the files...
-
Jan 11th, 2008, 12:40 PM
#6
Re: VB simple query (I think)
That makes things a little easier to maintain:
Code:
Dim Files() As String = System.IO.Directory.GetFiles("E:\Pics\", "*.jpg")
For Counter As Integer = 0 To Files.GetUpperBound(0)
Files(Counter) = System.IO.Path.GetFileNameWithoutExtension(Files(Counter))
Next Counter
Me.cbo_user.DataSource = Files
-
Jan 11th, 2008, 12:42 PM
#7
Thread Starter
New Member
Re: VB simple query (I think)
Thats it, perfect - problem resolved. Cheers Juggalo for the quick response!
-
Jan 11th, 2008, 12:47 PM
#8
Re: VB simple query (I think)
Welcome to the forums Kavna. 
If you consider this resolved, you could help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|