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

前端 未结 28 2092
心在旅途
心在旅途 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:02

    Based on the answer from @Amir Shenouda I end up with this:

    Enum's definition:

    public enum Status { Active = 0, Canceled = 3 }; 
    

    Setting the drop down values from it:

    cbStatus.DataSource = Enum.GetValues(typeof(Status));
    

    Getting the enum from the selected item:

    Status? status = cbStatus.SelectedValue as Status?;
    

提交回复
热议问题