Create a gist now

Instantly share code, notes, and snippets.

How to map enums to comboboxes in C#.
public partial class MappingEnumToComboboxesForm : Form
{
public MappingEnumToComboboxesForm()
{
InitializeComponent();
//Setting the enums as the data sources of the comboboxes
comboBoxNormal.DataSource =
Enum.GetValues(typeof(WdtOscillatorCycles));
comboBoxImproved.DataSource =
Enum.GetValues(typeof(WdtOscillatorCyclesImproved));
}
public WdtOscillatorCyclesImproved WdtOscillatorCyclesOption
{
get
{
//The result must be cast to the enum's type
return (WdtOscillatorCyclesImproved)(comboBoxImproved.SelectedItem);
}
set
{
//You don't need a cast here.
comboBoxImproved.SelectedItem = value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment