public static void BindToEnumValue <TEnum>(this ComboBox cbo, BindingSource bs, string propertyName) { cbo.DataSource = EnumPair <TEnum> .GetValuePairList(); cbo.ValueMember = EnumPair <TEnum> .ValueMember; cbo.DisplayMember = EnumPair <TEnum> .DisplayMember; cbo.DataBindings.Add(new Binding("SelectedValue", bs, propertyName)); }
/// <summary> /// Generates a <see cref="List<T>"/> of the values /// of the <see cref="Enum"/> T. /// </summary> public static List <EnumPair <T> > GetValuePairList() { List <EnumPair <T> > list = new List <EnumPair <T> >(); EnumPair <T> pair = new EnumPair <T>(); foreach (var item in Enum.GetValues(typeof(T))) { pair = new EnumPair <T>(); pair.EnumValue = (T)item; pair.EnumStringValue = ((T)item).ToString(); list.Add(pair); } return(list); }
public EnumSerializer(Type enumType, EnumPair[] map) { if (enumType == null) throw new ArgumentNullException("enumType"); this.enumType = enumType; this.map = map; if (map != null) { for (int i = 1; i < map.Length; i++) for (int j = 0; j < i; j++) { if (map[i].WireValue == map[j].WireValue && !Equals(map[i].RawValue, map[j].RawValue)) { throw new ProtoException("Multiple enums with wire-value " + map[i].WireValue.ToString()); } if (Equals(map[i].RawValue, map[j].RawValue) && map[i].WireValue != map[j].WireValue) { throw new ProtoException("Multiple enums with deserialized-value " + map[i].RawValue); } } } }
public EnumSerializer(Type enumType, EnumPair[] map) { if (enumType == null) throw new ArgumentNullException("enumType"); this.enumType = enumType; this.map = map; }
private void cboAuditReason_SelectedIndexChanged(object sender, EventArgs e) { EnumPair <AuditReason> reason = cboAuditReason.SelectedItem as EnumPair <AuditReason>; txtExitingShopManagerName.Enabled = reason.Value == AuditReason.MANAGERCHANGE; }