using InABox.Core; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Media; using System.Windows; using Syncfusion.Windows.Tools.Controls; using Syncfusion.Data.Extensions; using NPOI.SS.Formula.Functions; namespace InABox.DynamicGrid { public class MultiLookupEditorControl : DynamicEditorControl, ILookupEditorControl { static MultiLookupEditorControl() { //DynamicEditorControlFactory.Register(); } private ComboBoxAdv Editor; public MultiLookupEditorControl() { OtherColumns = new Dictionary(); Lookups = new Dictionary(); Width = int.MaxValue; } public int Width { get; set; } public Dictionary Lookups { get; set; } public Dictionary OtherColumns { get; } private List> Items; public override void Configure() { Editor.HorizontalAlignment = Width.Equals(int.MaxValue) ? HorizontalAlignment.Stretch : HorizontalAlignment.Left; if (!Width.Equals(int.MaxValue)) Editor.Width = Width; Editor.IsEnabled = false; Host.LoadLookups(this); } public void LoadLookups(CoreTable values) { var keycol = ColumnName.Split('.').Last(); //var prefix = string.Join(".", ColumnName.Split('.').Reverse().Skip(1).Reverse()); /*foreach (var col in values.Columns) if (!string.Equals(col.ColumnName, keycol) && !string.Equals(col.ColumnName, "Display")) if (!OtherColumns.ContainsKey(col.ColumnName)) OtherColumns[col.ColumnName] = string.IsNullOrWhiteSpace(prefix) ? col.ColumnName : string.Join(".", prefix, col.ColumnName);*/ var value = RetrieveValue(); //Lookups = lookups; Lookups.Clear(); Items = new List>(); //if (!IsEnumEditor()) // Editor.Items.Add(""); var selected = Editor.SelectedItems is not null ? Editor.SelectedItems.Cast>().Select(x => x.Item1) : Enumerable.Empty(); foreach (var row in values.Rows) { var key = row[keycol]; Items.Add(new(key, $"{row["Display"]}")); if (key != null) { Lookups[key] = string.Format("{0}", row["Display"]); } } Editor.ItemsSource = Items; Editor.DisplayMemberPath = "Item2"; Editor.SelectedItems = Items.Where(x => selected.Contains(x.Item1)).ToObservableCollection(); //var sel = values.Rows.FirstOrDefault(r => r[keycol].Equals(value)); //if(sel is null) //if (IsEnumEditor()) // Editor.SelectedIndex = sel != null ? sel.Index : 0; //else // Editor.SelectedIndex = sel != null ? sel.Index + 1 : 0; //foreach (var key in lookups.Keys) // Editor.Items.Add(lookups[key]); //if ((value != null) && Lookups.ContainsKey(value)) // Editor.SelectedIndex = Lookups.Keys.ToList().IndexOf(value); Editor.IsEnabled = EditorDefinition.Editable == Editable.Enabled; } public override int DesiredHeight() { return 25; } public override void SetFocus() { Editor.Focus(); } private bool IsEnumEditor() { return EditorDefinition is EnumLookupEditor; } public List