When you attach a ComboBox's datasource to a datatable (dt0
) it actually attaches to the .DefaultView
DataView of the table. This means you can set the .Sort
property of the view to sort the combo:
dt0.DefaultView.Sort = "[NameOfMov] ASC";
SearchResultCbB1.DisplayMember = "NameOfMov" 'this shows in the combo
SearchResultCbB1.ValueMember= "ID" 'you probably want an ID, not the movie name, for this
SearchResultCbB1.DataSource = dt0
You can change this Sort property at any time. For more info on what you can do with it, see the documentation
Please don't write SQL's like you have there; it's a massive security flaw. For more info on why, read http://bobby-tables.com - it will also give advice on how to prevent it, but really you should look at upgrading your knowledge to use Entity Framework or Dapper for your data access and never again, ever concatenate a value into an SQL string