📜  c# binding add combobox with enum values - C# Code Example

📅  最后修改于: 2022-03-11 14:49:10.889000             🧑  作者: Mango

代码示例1
public class DataItem
{
    public MyEnum Value { get; set; }
    public string Text { get; set; }
}

this.comboBox1.DataSource = Enum.GetValues(typeof(MyEnum)).Cast()
                                .Select(x => new DataItem() { Value = x, Text = x.ToString() })
                                .ToList();
this.comboBox1.ValueMember = "Value";
this.comboBox1.DisplayMember = "Text";

this.comboBox1.DataBindings.Add(
    new Binding("SelectedValue", yourObjectToBind, "PropertyOfYourObject"));