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