DataGrid.InsertRow does not add item to DataGrid.Data

An item added to the DataGrid through InsertRow makes the item show up as a new row on the grid, but it cannot be found in DataGrid.Data which I find strange.

await grid.InsertRow(item);
bool found = grid.Data.Contains(item);
Console.WriteLine($"Inserted row was found: {found}");

-- Inserted row was found: False

Is this by design?

Yes, this is by design. The item is inserted in an internal collection. You need to handle the RowCreate event to insert the data item where required.

Alright. I'm having some troubles with how the grid behaves based on the inline editing example.

  • It is possible to add multiple empty rows.
  • It is possible to edit one row and then start editing another row, leaving the first row with unsaved changes.

So if I add 2 new rows and then go to edit another row, one of the new rows disappears, but the other new row is neither in the DataGrid.Data, nor in the backing collection since the RowCreate event is never raised.

It seems I have to keep track of when there is a new rows myself then and prevent more rows from being added until the new row has been created or canceled?

You can check the actual implementation here:

The new item is inserted in PagedView property.

Thanks, the PagedView property helped me sort my issue.