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

前端 未结 28 2161
心在旅途
心在旅途 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 04:55

    comboBox1.DataSource = Enum.GetValues(typeof(MyEnum));
    
    comboBox1.SelectedIndex = (int)MyEnum.Something;
    
    comboBox1.SelectedIndex = Convert.ToInt32(MyEnum.Something);
    

    Both of these work for me are you sure there isn't something else wrong?

提交回复
热议问题