Skip to content

Instantly share code, notes, and snippets.

@howellcc
Created September 13, 2017 11:51
Show Gist options
  • Save howellcc/578d2ca46c81eb14177bacb816168251 to your computer and use it in GitHub Desktop.
Save howellcc/578d2ca46c81eb14177bacb816168251 to your computer and use it in GitHub Desktop.
Populating a combobox from an enumeration
using LCS.Core.Extensions;
//define collection
private ObservableCollection<KeyValuePair<eApplicantType, string>> ApplicantTypes { get; set; }
//populate collection eg. initialize()
this.ApplicantTypes = new ObservableCollection<KeyValuePair<eApplicantType, string>>();
foreach (eApplicantType type in Enum.GetValues(typeof(eApplicantType)))
{
if (type == eApplicantType.NotSet) { continue; }
this.ApplicantTypes.Add(new KeyValuePair<eApplicantType, string>(type, type.ToDescription()));
}
//load control
cboContAppType.ItemsSource = this.ApplicantTypes;
cboContAppType.DisplayMemberPath = "Value";
cboContAppType.SelectedValuePath = "Key";
cboContAppType.SelectedIndex = 0;
if (cboContAppType != null && cboContAppType.SelectedValue != null)
{
this.Contact.ApplicantType = (eApplicantType)cboContAppType.SelectedValue;
}
//set current value
cboContAppType.SelectedValue = this.Contact.ApplicantType;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment