Binding an enum to a WinForms combo box, and then setting it

前端 未结 28 2107
心在旅途
心在旅途 2020-11-28 04:33

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(MyE         


        
28条回答
  •  眼角桃花
    2020-11-28 05:09

    At the moment I am using the Items property rather than the DataSource, it means I have to call Add for each enum value, but its a small enum, and its temporary code anyway.

    Then I can just do the Convert.ToInt32 on the value and set it with SelectedIndex.

    Temporary solution, but YAGNI for now.

    Cheers for the ideas, I will probably use them when I do the proper version after getting a round of customer feedback.

提交回复
热议问题