I use Windows Forms. I want DisplayMember equal property from base class? I have class
public class MyViewModel
{
public int Id { get; set; }
public Type Type { get; set; }
}
I want, that my comboBox show Type.Name.
List<MyViewModel> list = new List<MyViewModel>();
list.Add(new MyViewModel(){ Id = 1, Type.GetType(int)});
list.Add(new MyViewModel(){ Id = 2, Type.GetType(string)});
//how i must to config displayMember???
myComboBox.DisplayMember = "Type.Name";
myComboBox.ValueMember = "Id";
myComboBox.DataSoutce = list;
But i can't get Type.Name for display in comboBox. Can you help me?
A ComboBox has an event for this purpose called Format:
myComboBox.DisplayMember = "Type";//Notice this
myComboBox.Format += (s,e) => {
e.Value = ((Type)e.Value).Name;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With