Results 1 to 8 of 8

Thread: [RESOLVED] VB simple query (I think)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    8

    Resolved [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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    8

    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.

  4. #4
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    8

    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...

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    8

    Re: VB simple query (I think)

    Thats it, perfect - problem resolved. Cheers Juggalo for the quick response!

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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
  •  



Click Here to Expand Forum to Full Width