Display enum in ComboBox with spaces

后端 未结 7 1101
北海茫月
北海茫月 2020-12-31 06:03

I have an enum, example:

enum MyEnum
{
My_Value_1,
My_Value_2
}

With :

comboBox1.DataSource = Enum.GetValues(typeof(MyEnum)         


        
7条回答
  •  萌比男神i
    2020-12-31 06:50

    I like Kelsey's answer although I would use another variable other than 'e' such as 'en' so the answer can be used in event handlers with less hassle; 'e' in event handlers tends to be the EventArgs argument. As for the LINQ and IEnumerable approach, it seems to me to be more complex and difficult to adapt for non-WPF ComboBoxes with .NET 3.5

提交回复
热议问题