Exemple #1
0
 private void EnumListBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.SelectedItem != null)
     {
         EnumNameAttribute selectedItem = (EnumNameAttribute)this.SelectedItem;
         this._value = selectedItem.EnumValue;
         this._edSvr.CloseDropDown();
     }
 }
Exemple #2
0
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string) && value is Enum)
     {
         MemberInfo[] mems = value.GetType().GetMember(value.ToString());
         if (mems != null && mems.Length > 0)
         {
             object[] customAttributes = mems[0].GetCustomAttributes(typeof(EnumNameAttribute), true);
             if (customAttributes.Count() > 0)
             {
                 EnumNameAttribute attribute = (EnumNameAttribute)customAttributes[0];
                 return(attribute.DisplayName);
             }
         }
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
Exemple #3
0
            private void InitEnumList(Type valueType)
            {
                this.Items.Clear();
                this.DisplayMember = "DisplayName";
                this.ValueMember   = "EnumValue";
                var mems = valueType.GetMembers(BindingFlags.Public | BindingFlags.Static);

                foreach (MemberInfo info in mems)
                {
                    object[] customAttributes = info.GetCustomAttributes(typeof(EnumNameAttribute), true);
                    if (customAttributes.Count() > 0)
                    {
                        EnumNameAttribute item = (EnumNameAttribute)customAttributes[0];
                        this.Items.Add(item);
                        if (item.EnumValue.Equals(this._value))
                        {
                            this.SelectedItem = item;
                        }
                    }
                }
            }