using InABox.Core; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CSharp.Syntax; using Syncfusion.Windows.Tools.Controls; namespace InABox.DynamicGrid { public interface IDynamicItemsListGrid : IDynamicGrid { IEnumerable Items { get; set; } } public class DynamicItemsListGrid : DynamicGrid, IDynamicItemsListGrid where T : BaseObject, new() { private List _items = new List(); public List Items { get => _items; set => _items = value; } IEnumerable IDynamicItemsListGrid.Items { get => _items.Cast(); set => _items = value.OfType().ToList(); } protected override void Init() { } protected override void DoReconfigure(FluentList options) { } protected override void DeleteItems(params CoreRow[] rows) { foreach (var row in rows.OrderByDescending(x => x.Index)) { Items.RemoveAt(_recordmap[row].Index); } } protected override T LoadItem(CoreRow row) { return Items[_recordmap[row].Index]; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder? sort, Action action) { var result = new CoreTable(); result.LoadColumns(typeof(T)); result.LoadRows(Items); action.Invoke(result, null); } public override void SaveItem(T item) { if (!Items.Contains(item)) { Items.Add(item); } } } }