a lot of people have answered the question of how to bind an enum to a combo box in WinForms. Its like this:
comboBox1.DataSource = Enum.GetValues(typeof(MyEnum));
But that is pretty useless without being able to set the actual value to display.
I have tried:
comboBox1.SelectedItem = MyEnum.Something; // Does not work. SelectedItem remains null
I have also tried:
comboBox1.SelectedIndex = Convert.ToInt32(MyEnum.Something); // ArgumentOutOfRangeException, SelectedIndex remains -1
Does anyone have any ideas how to do this?
SelectedValue
causes anInvalidOperationException
for me. "Cannot set theSelectedValue
in aListControl
with an emptyValueMember
." – Tyler