Results 1 to 3 of 3

Thread: [RESOLVED] Listbox Odd behavior

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Resolved [RESOLVED] Listbox Odd behavior

    I have a listbox that is bound to a datasource and is filtered as below. The odd behavior is that it doesn't sort correctly as in 1,2,6,7,3,4,5. Any idea why this could be happening?

    How the table is filled:

    Code:
     Me.ERV_ExhibitsTableAdapter.Fill(Me.ERVDataSet.ERV_Exhibits)
    My filter code.

    Code:
     Private Sub cmbLocation_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbLocation.SelectedIndexChanged
            ERV_ExhibitsBindingSource.Filter = String.Format("Location = '{0}' AND Exhibit = '{1}'", cmbLocation.Text, cmbQualifyingCritera.Text)
        End Sub
    Life is about making some things happen, not waiting around for something to happen.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: Listbox Odd behavior

    I compact and repair of the db fixed the problem. Still do not know why but it's fixed.
    Life is about making some things happen, not waiting around for something to happen.

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,386

    Re: [RESOLVED] Listbox Odd behavior

    Filter isn't the same thing as sorting. When you use BindingSource.Filter, you return a group of rows that match a certain criteria. In this case you where returning rows where your column 'Location' matches cmbLocation.Text and where your column 'Exhibit' matches cmbQualifyingCritera.Text. If you wanted to sort those returned rows you'd call BindingSource.Sort. Let's say you wanted to sort the 'Location' column, it would look like this:
    Code:
    ERV_ExhibitsBindingSource.Sort = "Location"
    If you wanted to sort by Location and then by Exhibit, the sort string would be a bit different:
    Code:
    ERV_ExhibitsBindingSource.Sort = "Location, Exhibit"
    You can also specify how the rows sort by adding "ASC" for ascending or "DESC" for descending at the end of your column, using the sorting by location and then by exhibit, if you wanted the sorting to be descending then it would look like this:
    Code:
    ERV_ExhibitsBindingSource.Sort = "Location DESC, Exhibit DESC"
    Last edited by dday9; May 21st, 2013 at 02:29 PM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

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