Until you call ToList()
on your LINQ
statement, you're not actually getting data from the database:
var countries = (from c in context.Set<sc_Countries>()
orderby c.Title
select new { c.ID, c.Title }).ToList();
Now you should be able to set the DataSource
, etc. like you were:
cboCountry.ValueMember = "ID";
cboCountry.DisplayMember = "Title";
cboCountry.DataSource = countries;
cboCountry.SelectedValue = "US"
Edit:
Now that I'm re-reading your question, it looks like you were already calling countries.ToList()
, but using Items.AddRange
. I see the same thing you do when I try it. It appears you have to set the DataSource
instead of using Items.AddRange
, for SelectedValue
to work.