i’ve a ComboBox where is filled using a Collections of Anonymous Type:
var results = (from row in data.Tables[0].AsEnumerable()
select new {
Id = row.Field<int>("id"),
Name = row.Field<string>("Name
}).Distinct();
myComboBox.ValueMember = "Id";
myComboBox.DisplayMember = "Name";
foreach (var n in results)
{
myComboBox.Items.Add(n);
}
Then, in SelectedIndexChanged method of the comboBox, i want to retrieve the Id of the selected item, but i can’t access to the “Id” property, in myComboBox.SelectedItem is the selected object.
private void myComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (myComboBox.SelectedItem != null)
{
var x = myComboBox.SelectedItem;
¿¿¿ ???
}
}
Any ideas?
You can use reflection too.