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

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

    In Framework 4 you can use the following code:

    To bind MultiColumnMode enum to combobox for example:

    cbMultiColumnMode.Properties.Items.AddRange(typeof(MultiColumnMode).GetEnumNames());
    

    and to get selected index:

    MultiColumnMode multiColMode = (MultiColumnMode)cbMultiColumnMode.SelectedIndex;
    

    note: I use DevExpress combobox in this example, you can do the same in Win Form Combobox

提交回复
热议问题