Skip to content

feat: bind DataView and DataTable rows with live ListChanged updates in KumikoUI.Data (#362) - #508

Open
michaelstonis wants to merge 5 commits into
mainfrom
feat/362-data-package
Open

michaelstonis wants to merge 5 commits into
mainfrom
feat/362-data-package

Conversation

@michaelstonis

Copy link
Copy Markdown
Contributor

Closes #362.

Changes

Core: IBindingList adapter (spec #107 section 8.5)

KumikoSource now observes IBindingList.ListChanged when the items implement IBindingList but not INotifyCollectionChanged (new partial file Models/KumikoSource.BindingList.cs, with small hooks in SetItems, Attach, Resync and UnsubscribeFromCollection, so SetItems, Detach and Dispose unsubscribe). This makes DataView and BindingList<T> live.

ListChangedType Handled as
ItemAdded that grew the list by one an INCC Add at NewIndex (the existing incremental path)
ItemAdded that did not grow the list a reset. A DataView raises ItemAdded again when an AddNew row is committed, so without this the row would be added twice
ItemChanged with a property, for an item already tracked through its own PropertyChanged ignored, because the item's own event handles it. A change raised both ways costs one update
ItemChanged without a property, for a tracked item (ResetItem) the item's cell text is invalidated. Rebuilds when a sort, filter, search, grouping or summary is active, otherwise redraws
ItemChanged with a property, for an item without INotifyPropertyChanged handled like that item's PropertyChanged
ItemChanged for an untracked item (list[i] = new) a reset, so the replaced item is re-read and re-tracked
ItemDeleted, ItemMoved, Reset, PropertyDescriptor* a reset: full re-track and one rebuild

When a collection raises both kinds of event, INotifyCollectionChanged wins. Changes from another thread go through the existing thread-affinity path: the source rejects them and resyncs. The list count is re-read on resync. Core still has no System.Data reference.

ReorderRow now returns NotSupportedSource for an IBindingListView source. Without this, on a DataView IList.RemoveAt deletes the row and the following Insert throws ("Cannot insert external objects"), so dragging a row would have deleted it.

New package KumikoUI.Data (stage 3)

src/KumikoUI.Data targets net10.0, is IsAotCompatible and IsTrimmable, versions in lockstep, references only KumikoUI.Core (System.Data.Common comes from the shared framework), has PublicAPI files and package validation with no baseline yet (the same setup as Export.Excel), and ships the NuGet README docs/nuget/README.KumikoUI.Data.md.

  • KumikoDataTable.Use() registers the provider for DataRowView with KumikoAccessorRegistry. Calling it again does nothing. It also registers an empty IKumikoColumnMetadataProvider for DataRowView, so AutoGenerateColumns does not generate columns from DataRowView's own CLR properties (Row, IsNew, ...).
  • KumikoDataTable.ColumnsFor(DataTable) builds one column per DataColumn through KumikoColumnFactory.Create, the same type mapping as generated columns (Columns: auto-generate columns from the item type, with DataAnnotations and an AOT-safe source-generator path #315):
    • ColumnName becomes PropertyName and Key; Caption becomes Header.
    • Formats are N0 for whole numbers and N2 for decimal and floating-point numbers, right-aligned.
    • A bool column with AllowDBNull is three-state.
    • ReadOnly and Expression columns are read-only; MappingType.Hidden columns are hidden.
    • byte[] columns are skipped; other types become Text columns.
  • KumikoDataRowViewAccessorProvider (Instance) is schema-agnostic: it looks the column up on each row with Columns[name] (exact name, then ignoring case).
    • Reads: DBNull, a missing column, a deleted row (unless the view shows deleted rows) and a row removed from its table all read as null.
    • Writes: the value is converted to DataColumn.DataType with KumikoValueConverter in table.Locale. Null and blank text store DBNull. The value is written with view[ordinal] = value and committed with EndEdit(). If either throws, CancelEdit() runs and the exception propagates, and KumikoValuePath turns its message into the cell's edit error. An edit the app began itself (IsEdit or IsNew) is left open.

Public API added (src/KumikoUI.Data/PublicAPI.Unshipped.txt):

KumikoUI.Data.KumikoDataRowViewAccessorProvider
KumikoUI.Data.KumikoDataRowViewAccessorProvider.GetAccessor(System.Type! itemType, string! propertyName) -> KumikoUI.Core.Data.KumikoPropertyAccessor?
static KumikoUI.Data.KumikoDataRowViewAccessorProvider.Instance.get -> KumikoUI.Data.KumikoDataRowViewAccessorProvider!
KumikoUI.Data.KumikoDataTable
static KumikoUI.Data.KumikoDataTable.ColumnsFor(System.Data.DataTable! table) -> System.Collections.Generic.IReadOnlyList<KumikoUI.Core.Models.KumikoColumn!>!
static KumikoUI.Data.KumikoDataTable.Use() -> void

Core gains no public API. PublicAPI.Shipped.txt is untouched.

Wiring

  • KumikoUI.sln has both new projects.
  • eng/update-public-api.sh now covers Data.
  • eng/AotSmoke has a DataView case: read, convert and edit, a refused edit, grid sort and filter, a live add, and the view's own Sort reset.
  • .github/workflows/ci.yml restores, builds, runs the type-name check on, tests and dry-run packs the Data project and its tests.
  • .github/workflows/publish.yml restores, packs, tests and verifies the package, and the validation step now requires six packages. The .github edits are needed because the issue asks for the new package to build, pack and publish in CI.
  • The docs snippet projects reference the package, so the README and NuGet README snippets compile.
  • CONTRIBUTING (type-name check command, package counts), docs/VERSIONING.md and the CHANGELOG header now list six packages.

Samples and docs

  • A Data Table page on both sample apps (samples/Shared/DataTableData.cs; KumikoDataTable.Use() runs in MauiProgram and in Uno's App.OnLaunched). Buttons add a row, delete the selected row, edit a row in code, cycle the view's own Sort and call RejectChanges. The table has a read-only unique key, a non-null column, a three-state Paid column, a hidden column, and a ColumnChanged rule that records a negative quantity as a column error.
  • README: a packages table row, a BindingList/ListChanged paragraph and a "DataTable and DataView" section under Live Data, and a sample table row. Also samples/README.md and a CHANGELOG entry under Unreleased > Added.

Decisions on the spec's open questions

  • Q4 (identity comparer): not added. In testing, a DataView keeps its DataRowView instances when its Sort or RowFilter changes and when other rows are added or deleted. So selection by reference survives everything except rows that leave the view and Clear followed by a reload. That case is documented and covered by a test.
  • Q8 (package name): KumikoUI.Data, namespace KumikoUI.Data.
  • Q9 (accept a DataTable as ItemsSource): no. Apps bind table.DefaultView, and no host property type changes.

Acceptance criteria

  • BindingList<T> and DataView changes (add, delete, edit, re-sort, reset) appear in the grid, with no double handling when both notification kinds exist. Covered by BindingListAdapterTests (20 tests) and DataViewBindingTests, including the both-events collection, ItemChanged paired with PropertyChanged (one Redraw or one Rebuild), AddNew then EndEdit (the row is added once), and ItemMoved under the view's sort.
  • DataRowView cells read, sort, filter, group, summarize and edit. DBNull, read-only and constraint errors behave as specified, and IDataErrorInfo errors show (DataRowViewAccessorTests, DataViewBindingTests, DataViewEditingTests through EditSession).
  • ColumnsFor produces the mapped columns (ColumnsForTests). Two deviations from the spec table, made so the mapping matches the generated-column mapping (Columns: auto-generate columns from the item type, with DataAnnotations and an AOT-safe source-generator path #315) as the issue asks: DateTime maps to the DateTime column type rather than Date, and no d format is forced on dates (each column type keeps its default format). ValueType is not set; see the Data: bind dictionary, ExpandoObject and DynamicObject rows by key with no app code (#107 Track B) #361 note below.
  • New KumikoUI.Data.Tests project (58 tests) and Core adapter tests in tests/KumikoUI.Core.Tests/BindingListAdapterTests.cs.
  • Package builds and packs, and is wired into CI and publish. The eng/AotSmoke DataView case runs: published with Native AOT for osx-arm64 with no IL warnings, and the binary prints "AOT smoke OK". DataView.RowFilter and DataColumn.Expression are RequiresUnreferencedCode in System.Data itself. The smoke test hit that on RowFilter, so it uses Sort, and the package README says so instead of suppressing the warning. CI runs of the workflows have not been seen (nothing pushed).
  • Works on MAUI and Uno; DataView sample page with edits on both sample apps. Partly done: both sample apps build: MAUI for maccatalyst, Uno for desktop. The pages have not been run interactively. Neither host needed a change: they pass ItemsSource to KumikoSource.SetItems.
  • XML docs on every new public member. PublicAPI.Unshipped.txt written by eng/update-public-api.sh Data.
  • README (packages table and data binding) and CHANGELOG entry under Unreleased.
  • No allocations added to the per-frame render path. Nothing in the renderer changed. A DataRowView read boxes the stored value, which the existing cell text cache keeps off the frame path.

Not done in this PR:

#361 overlap: KumikoColumn.ValueType does not exist on this base. The provider therefore converts to DataColumn.DataType itself, in the table's Locale, and no Core hook was added. Once #361 lands, ColumnsFor can also set ValueType. The provider's conversion then sees values that already have the right type and does nothing.

Verification

  • dotnet build src/KumikoUI.Core: succeeded.
  • dotnet build src/KumikoUI.Data -c Release --no-incremental: 0 warnings, 0 errors.
  • dotnet test tests/KumikoUI.Core.Tests: Passed 4381, Skipped 5, Failed 0.
  • dotnet test tests/KumikoUI.Data.Tests: Passed 58, Failed 0.
  • dotnet test tests/KumikoUI.Export.Excel.Tests: Passed 122. dotnet test tests/KumikoUI.Maui.Tests: Passed 449. dotnet test tests/KumikoUI.SkiaSharp.Tests: Passed 42.
  • dotnet pack src/KumikoUI.Data -c Release: .nupkg and .snupkg produced. They contain lib/net10.0/KumikoUI.Data.dll and .xml, the README and the logo, with an exact-version dependency on KumikoUI.Core.
  • dotnet run --project eng/TypeNameCheck -c Release -- <Core, SkiaSharp, Export.Excel, Data dlls>: "No public type name collides" (250 types, 4 assemblies).
  • dotnet publish eng/AotSmoke -c Release -r osx-arm64: no IL2xxx or IL3xxx warnings. The binary prints "AOT smoke OK". The local native link needed LIBRARY_PATH pointing at a local OpenSSL; that is a machine toolchain issue, not part of this change.
  • dotnet run --project eng/DocsSnippets -c Release picked up the new NuGet README. dotnet build tests/KumikoUI.Docs.Snippets.Uno -f net10.0-desktop -c Release: succeeded, with only existing Uno warnings.
  • dotnet build samples/SampleApp.Uno -f net10.0-desktop: succeeded.
  • dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst -p:KumikoDevFlow=false: succeeded. The default Debug build fails at restore on this machine with NU1605, a DevFlow package version downgrade of Microsoft.Maui.Controls; this change touches no package versions.
  • dotnet format whitespace --folder . --verify-no-changes --include <changed folders>: clean.

@michaelstonis michaelstonis changed the title feat: observe IBindingList.ListChanged in KumikoSource (#362) feat: bind DataView and DataTable rows with live ListChanged updates in KumikoUI.Data (#362) Nov 30, 2026
bob.Row.Delete();

Assert.Null(Accessor("Customer").GetValue(bob));
var deleted = new DataView(table, "", "", DataViewRowState.Deleted);
[Fact]
public void Read_ServesEveryTableWithTheSameAccessor()
{
var other = new DataTable();
[Trait("Category", "Performance")]
public void ItemAdded_OnALargeView_IsIncremental()
{
var table = new DataTable { Locale = System.Globalization.CultureInfo.InvariantCulture };

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Data: bind DataView and DataTable rows with live ListChanged updates in an opt-in KumikoUI.Data package (#107 Track B)

2 participants