Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iskernel/5539947 to your computer and use it in GitHub Desktop.
Save iskernel/5539947 to your computer and use it in GitHub Desktop.
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