public static void InitItemList(string name, WinFormLib.Controls.ComboBoxExt control) { control.Items.Clear(); List <ItemValue> itemList = new List <ItemValue>(); ItemValue entity = new ItemValue() { name = name, text = name, }; itemList.Add(entity); control.DisplayMember = "name"; control.ValueMember = "text"; control.DataSource = itemList; }
public static void InitItemList(Type type, WinFormLib.Controls.ComboBoxExt control) { control.Items.Clear(); FieldInfo[] EnumInfo = type.GetFields(); List <ItemValue> itemList = new List <ItemValue>(); foreach (var item in EnumInfo) { DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])item.GetCustomAttributes(typeof(DescriptionAttribute), false); if (EnumAttributes.Length > 0) { ItemValue entity = new ItemValue() { name = EnumAttributes[0].Description, text = item.Name.ToString(), }; itemList.Add(entity); } } control.DisplayMember = "name"; control.ValueMember = "text"; control.DataSource = itemList; }