Ejemplo n.º 1
0
 private void BindAttributeTypesToGridCombobox(DataGridViewComboBoxColumn list)
 {
     Type enumerationType = typeof (AttributeType);
     Array enumValues = Enum.GetValues(enumerationType);
     List<NameValuePair> dataSource = new List<NameValuePair>(enumValues.Length+1);
     dataSource.Add(new NameValuePair{ Name = "- select value -", Value = 0});
     Regex reNameNormalization = new Regex(@"[A-Z\d]+");
     for (int i = 0; i < enumValues.Length; i++)
     {
         int value = (int)enumValues.GetValue(i);
         if ((value & (int)MultiValueAttribute.MultiFlag) == 0)
         {
             string name = Enum.GetName(enumerationType, value);
             name = reNameNormalization.Replace(name, " $&").Trim();
             NameValuePair item = new NameValuePair {Name = name, Value = value};
             dataSource.Add(item);
         }
     }
     list.DisplayMember = "Name";
     list.ValueMember = "Value";
     list.DataSource = dataSource;
 }
Ejemplo n.º 2
0
 private void BindEnumToCombobox(ComboBox list, Type enumerationType)
 {
     Array enumValues = Enum.GetValues(enumerationType);
     List<NameValuePair> dataSource = new List<NameValuePair>(enumValues.Length);
     Regex reNameNormalization = new Regex(@"[A-Z\d]+");
     for (int i=0; i < enumValues.Length; i++)
     {
         int value = (int) enumValues.GetValue(i);
         string name = Enum.GetName(enumerationType, value);
         name = reNameNormalization.Replace(name, " $&").Trim();
         NameValuePair item = new NameValuePair { Name = name, Value = value };
         dataSource.Add(item);
     }
     list.DisplayMember = "Name";
     list.ValueMember = "Value";
     list.DataSource = dataSource;
 }