Wednesday, July 12

Sorting a Data-Bound ComboBox

I have set up a view with an order by clause and bound it to a ComboBox using ADO.NET 2.0. The combo box did not take any notice of the order by clause, and seemed to display items in the order they appeared in the database tables that made up the view.

To fix this, I had to manually set the Sort property of the column I wanted the combo box to be ordered by on the BindingSource used by the control as follows before calling the Fill method on the table adapter :-


myViewBindingSource.Sort = "ID";
myViewTableAdapter.Fill(myDataSet.myView);


Why can't it pick up the order by clause in my view automatically?

No comments: