很多人已经回答了如何在WinForms中将枚举绑定到组合框的问题。它像这样:
comboBox1.DataSource = Enum.GetValues(typeof(MyEnum));
但是如果不能设置实际值来显示,那就没有多大用处了。
我尝试过:
comboBox1.SelectedItem = MyEnum.Something; // Does not work. SelectedItem remains null
我还尝试过:
comboBox1.SelectedIndex = Convert.ToInt32(MyEnum.Something); // ArgumentOutOfRangeException, SelectedIndex remains -1
有人有任何想法怎么做吗?
SelectedValue
引发了一个InvalidOperationException
。"无法在具有空ValueMember
的ListControl
中设置SelectedValue
。" - Tyler