RadzenTree checkboxes with children

Hi have a RadzenTree, with the AllowCheckChildren property set to true:

<RadzenTree Data="@tree.Children"
                    AllowCheckBoxes="true"
                    AllowCheckChildren=true
                    @bind-CheckedValues=@SelectedItems
                    class="w-100"
                    Style="height: 500px;"
                    @ref=treePicker>

If I open the page, and select a checkbox, I expect all the children under that to be included in the SelectedItems collection property I am bound to.

However, this only appears to happen if I expand the tree in the UI. If I check a parent node, without ever expanding it's children, then the children do not appear to ever be included in the SelectedItems collection.

Similarly, if I uncheck a parent, all of it's children will continue to be in the SelectedItems collection, unless I expand the node in the UI.

Basically, it seems that AllowCheckChildren only works if the tree is expanded. If someone checks a node without expanding it in the UI, this property does nothing?

Am I missing something to get this to work as expected?

Thanks!

When you check a non expanded parent there are no children at that time and that is why they cannot be added to CheckedValues .

Thanks enchev,

So Radzen treats all treats virtually, and only creates children at the time of expansion. I guess I can see how that makes sense, particularly for very large trees.

I guess a workaround would be to have clicking a checkbox trigger the expand event for a given node, is there any way to do this?

Or, rather than checking returning a IEnumerable, perhaps a ValueProperty could be assigned that points to a bool on the actual node objects themselves, which would allow the node to take take care of child assignment in a setter property?

If you know in your case the children of the checked parent you can add them to CheckedValues manually on parent check.

Yes, that works on the Check=true case, but it doesn't work on the Check=false case.

If I uncheck a node, it gets removed from CheckedValues, but all of it's children remain. Unless I'm missing something, there's no easy way to then remove all the orphaned children at this point?

Only way I can think of is maintaining a current and previous state, and diffing them to get the removed nodes?

If you add them manually you can remove them manually as well.

How though? How would I figure out which ones to manually remove?

I have to store state right? Store the previous IEnumerable, compare it to the current IEnumerabe, to find whatever parent was removed and then manually remove all it's children?

Yes, that's the only way in my opinion what you are trying to achieve.

Ok, that makes sense.

Thanks enchev, I really appreciate the help!