Binding an enum to a WinForms combo box, and then setting it
The Enum
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;
Enum.TryParse<Status>(cbStatus.SelectedValue.ToString(), out status);
To simplify:
First Initialize this command: (e.g. after InitalizeComponent()
)
yourComboBox.DataSource = Enum.GetValues(typeof(YourEnum));
To retrieve selected item on combobox:
YourEnum enum = (YourEnum) yourComboBox.SelectedItem;
If you want to set value for the combobox:
yourComboBox.SelectedItem = YourEnem.Foo;