Answers for "c# binding add combobox with enum values"

C#
0

c# binding add combobox with enum values

public class DataItem
{
    public MyEnum Value { get; set; }
    public string Text { get; set; }
}

this.comboBox1.DataSource = Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>()
                                .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"));
Posted by: Guest on August-27-2021

C# Answers by Framework

Browse Popular Code Answers by Language