// Bind Combo for enum type, but provide the subset list of enums/valid values to show // also using grouping on results, according to public static void BindControlWithGrouping(this ComboBox ComboBox, Object obj, string Field, dynamic enumslist) { GingerCore.General.ObjFieldBinding(ComboBox, ComboBox.SelectedValueProperty, obj, Field, BindingMode.TwoWay); List <GingerCore.General.ComboGroupedEnumItem> l = new List <GingerCore.General.ComboGroupedEnumItem>(); foreach (var v in enumslist) { GingerCore.General.ComboGroupedEnumItem item = new GingerCore.General.ComboGroupedEnumItem(); item.text = GingerCore.General.GetEnumValueDescription(v.GetType(), v); item.Category = GingerCore.General.GetEnumDescription(v.GetType(), v);; item.Value = v; l.Add(item); } // Get yhe current value so it will be sleected in the combo after the list created PropertyInfo PI = obj.GetType().GetProperty(Field); object CurrentFieldEnumValue = PI.GetValue(obj); ListCollectionView lcv = new ListCollectionView(l); lcv.GroupDescriptions.Add(new PropertyGroupDescription("Category")); lcv.SortDescriptions.Add(new SortDescription("Category", ListSortDirection.Ascending)); App.FillComboFromEnumVal(ComboBox, CurrentFieldEnumValue, null, true, lcv); }
// ------------------------------------------------------------ // Text Box // ------------------------------------------------------------ public static void BindControl(this ComboBox ComboBox, dynamic enumslist) { List <object> l = new List <object>(); foreach (var v in enumslist) { l.Add(v); } // Get yhe current value so it will be sleected in the combo after the list created App.FillComboFromEnumVal(ComboBox, l[0], l); }
// Bind Combo for enum type, but provide the subset list of enums/valid values to show public static void BindControl(this ComboBox ComboBox, Object obj, string Field, dynamic enumslist) { GingerCore.General.ObjFieldBinding(ComboBox, ComboBox.SelectedValueProperty, obj, Field, BindingMode.TwoWay); List <object> l = new List <object>(); foreach (var v in enumslist) { l.Add(v); } // Get yhe current value so it will be sleected in the combo after the list created PropertyInfo PI = obj.GetType().GetProperty(Field); object CurrentFieldEnumValue = PI.GetValue(obj); App.FillComboFromEnumVal(ComboBox, CurrentFieldEnumValue, l); }
// ------------------------------------------------------------ // Combo Box // ------------------------------------------------------------ // Bind ComboBox to enum type field, list of valid values are all enum of the field selected public static void BindControl(this ComboBox ComboBox, Object obj, string Field) { // Get the current value so we can make it selected PropertyInfo PI = obj.GetType().GetProperty(Field); object CurrentFieldEnumValue = PI.GetValue(obj); if (CurrentFieldEnumValue == null || CurrentFieldEnumValue.GetType() == typeof(string)) { // if it's string like in Excel Sheet name combo then do binding to the text // or we can ask for function call to return list of values - TODO: later if we need Val/text GingerCore.General.ObjFieldBinding(ComboBox, ComboBox.TextProperty, obj, Field, BindingMode.TwoWay); } else { App.FillComboFromEnumVal(ComboBox, CurrentFieldEnumValue); GingerCore.General.ObjFieldBinding(ComboBox, ComboBox.SelectedValueProperty, obj, Field, BindingMode.TwoWay); } }