I've got a WinForms comboBox that contains a list of "Regions" (a custom class I've set up). Each Region
has properties Name
, Abbreviation
, etc. I know I can set the comboBox to comboBox.DisplayMember = "Name";
, but I want the display formatting to be "(" + Abbreviation + ") " + Name
(e.g. (OR) Oregon
).
I know I could create a separate property for this (e.g. DisplayName
) and just set the comboBox.DisplayMember = "DisplayName";
but is there another way to do it? Something like comboBox.DisplayMember = "(" + Abbreviation + ") " + Name;
or whatever?
You can use combobox's Format event.
private void comboBox1_Format(object sender, ListControlConvertEventArgs e)
{
string Name = ((yourClass)e.ListItem).Property1;
string LastName = ((yourClass)e.ListItem).Property2;
e.Value = Name + " " + LastName;
}
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