In C# 3.5 using a ComboBox to display the results of a LinQ Query. How do I set the selecteditem property of the combobox when the LinQ query is returning an anonymous type?
I set the datasource of the combobox along these lines:
comboBox1.DataSource = from p in db.products
select p;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "ProductId";
If I do that I can choose the selected item by doing something like:
comboBox1.SelectedItem = (from p in db.products
where p.ProductId = 5
select p).First();
The problem is that I want to fill a combobox with an anonymous type result like:
comboBox1.DataSource = from p in db.products
select new
{
p.ProductId,
p.Name
};
The anonymous type I'm actually using is more complicated then that but it suffices for explanation.
Thanks.