Results 1 to 4 of 4

Thread: [2008] Sorting listbox data from External source

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    4

    [2008] Sorting listbox data from External source

    I am trying to figure out a correct way to sort the listbox that is being populated by data from an exteranl hard drive. The DB's on the Hard drive are contained in folders with a naming format as follows (Jan94 - Dec08)
    The issue is that on the HD all the folders(yrs) for Apr are listed together and then the rest listed the same way, just sorted based on 1st alpha character. The format I want to show in the list box is as follows:

    Jan94
    Dec94
    .
    .
    Jan08
    Dec08
    Jan09

    Can anyone offer a solution or direction on how this could be achieved.
    I've searched the forums and haven't seen anything that may offer a direction. Looked at MSDN and could't find a solution, maybe looking for the wrong thing.

    Any ideas would be appreciated.

    VB Newbie

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: [2008] Sorting listbox data from External source

    This is a small example you could use to sort the dates, obviously you will need to fill the list first with the folder names by using io.directory.getdirectories.
    Code:
    Dim DateList As New List(Of String)
    
            DateList.Add("May76")
            DateList.Add("Nov08")
            DateList.Add("Apr07")
            DateList.Add("Jan04")
            DateList.Add("Jan08")
            DateList.Add("Jun94")
            DateList.Add("Jan09")
            DateList.Add("Jan94")
            DateList.Add("Dec94")
    
            Dim SortList = From S In DateList _
                           Order By DateValue(S)
    
            ListBox1.Items.AddRange(SortList.ToArray)
    Casey.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    4

    Re: [2008] Sorting listbox data from External source

    Casey,

    Thanks for the follow-up. Since there will be new DB's added on a monthly basis going forward, your solution appears to require me to come back and add in each new month, I was hoping for something that wouldn't require constant maintence.

    Thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Sorting listbox data from External source

    Quote Originally Posted by Daniel1313
    Casey,

    Thanks for the follow-up. Since there will be new DB's added on a monthly basis going forward, your solution appears to require me to come back and add in each new month, I was hoping for something that wouldn't require constant maintence.

    Thanks
    Not so. As Casey said, her code is just an example. In the real world you will populate the List by calling Directory.GetDirectories. That will get the current list of folder names whatever they happen to be.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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