I've got a blazor web app that uses an API to interact with an SQL database. When I delete the last object in the datagrid's "Data=" collection and perform a RadzenDataGrid.Reload() it throws the exception.
Here's the datagrid item in the Razor Component...
<RadzenDataGrid @ref="objGrid" Data="@objCollection" TItem="ReportObject"....
The objCollection declaration:
List<ReportObject> objCollection = new List();
Here's the method that's throwing the exception...
public async Task DeleteRow(ReportObject repObj)
{
Reset(repObj);
try
{
if (objCollection.Contains(repObj))
{
if (await errorReportEmailDataService.DeleteErrorReportEmailAsync(repObj.id))
objCollection.Remove(repObj);
else
objGrid.CancelEditRow(repObj);
await objGrid.Reload();
}
else
{
await CancelEdit(repObj);
}
}
catch (Exception ex)
{
logger.Error(ex);
objCollection= (await ReportObjectDataService.GetReportObjectsAsync(reportID)).ToList() ?? Enumerable.Empty<ReportObject>().ToList();
}
}
I can't follow the Datagrid inline edit example exactly since I'm not using a dbContext directly...
Since the datagrid can handle an empty collection by showing an empty grid I'm not sure where this is falling apart.
I want to add that this code works fine when the result of objCollection.Remove(repObj) doesn't result in an empty List().