หลายคนตอบคำถามเกี่ยวกับวิธีผูก enum กับ combo box ใน 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ให้ฉัน "ไม่สามารถตั้งค่าSelectedValueใน a ที่ListControlมีค่าว่างValueMember"