Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Collection was modified; enumeration operation may not execute.
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List1.Enumerator[[Radzen.Blazor.RadzenTreeItem, Radzen.Blazor, Version=4.28.8.0, Culture=neutral, PublicKeyToken=null]].MoveNextRare() at System.Collections.Generic.List1.Enumerator[[Radzen.Blazor.RadzenTreeItem, Radzen.Blazor, Version=4.28.8.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
at Radzen.Blazor.RadzenTreeItem.Expand()
at Radzen.Blazor.RadzenTreeItem.Toggle()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
If I set SingleExpand to false, I don't get the error anymore.
But !
At loading I set the checkboxes for the children only, expecting the parents to update their tristate status automatically. But it's not.
And If I open a branch containing partial checks, then the parent get its partial check status.
But if I open a branch with all its children already checked, the parent doesn't get the check.
For my project, I added a link to the subcategories on each categories, populated by entity framework foreign key.
In OnInitializedAsync method :
var listChecks = new List<SubCategoryDto>();
foreach (var cat in categories)
{
listChecks.AddRange(cat.ListSubCategories.Where(sc => !sc.Excluded));
}
checkedValues = listeCheck;
On page load, subcategories are getting their checkbox ticked, but the underlying parent is not updated. Only when opening the branches, there is some update to the parents but it's not consistent, as said earlier.
If you want your parent to be checked you either need to expand the children or include the parent checked state initially. The Tree component will not load anything state from children if not expanded since this will be huge performance problem.