Node rendering issue with Tree Checkboxes

.razor

<RadzenTree AllowCheckBoxes="true" Data="DepartmentsDtos"
            @bind-CheckedValues="selectedObjs"
            AllowCheckChildren="true" AllowCheckParents="true"
            Style="min-height: 200px; max-height: 400px;">
    @for (int i = 1; i <= TreeDepth; i++)
    {
        <RadzenTreeLevel Text="GetText" ChildrenProperty="@nameof(DepartmentsDto.Children)"
                         HasChildren="@(obj => obj is DepartmentsDto dto && dto.Children.Count > 0)" />
    }
</RadzenTree>
<RadzenButton ButtonStyle="ButtonStyle.Primary" Icon="check" Text="確認"
              Click="@(() => dialogService.Close(selectedObjs))" />

Model

public partial class DepartmentsDto
{
    public int DepNo { get; set; }

    public string DepDepid { get; set; } = null!;

    public int DepParentid { get; set; }

    public string DepName { get; set; } = null!;

    public List<DepartmentsDto> Children { get; set; } = [];
}

This is a tree structure data with an indefinite depth. When I use this component, I find that when the parent node is not expanded, it will not make any check or selection judgments on the child nodes. It seems to be a lazy loading mechanism, but it goes against the user's operation logic, as shown in the video. Is there any parameter to adjust this aspect so that the check status of the child node can operate normally even without expanding the parent node?

2025-04-10 16 40 07.zip (2.3 MB)

There is a way to define the parent checked status (if you know it) without expanding the children illustrated in this demo:

I have tested this method, but its rendering still requires the parent node to be expanded before its value can be obtained through args.
However, I also wrote my own CheckedValuesChanged method, but the execution order is to execute ItemRender first, then CheckedValuesChanged, which will cause ItemRender to use the data before checking, resulting in the inability to meet the requirements.

That’s not true - as you can see in the demo the parent node check state is set without anything expanded.

Got it, sorry, thank you for your patient reply.
I was thinking that there might be something wrong with the logic in ItemRender, which led to it not working as I wanted. I will rewrite the logic to see if it can meet my needs.
Thank you very much for your help, and I'm sorry that it took you some time to deal with my problem.

When I tried the TreeItemRender method again, I still encountered problems that did not meet user experience expectations, as shown in the figure.


Figure1. When I set the CheckedValue list to empty


Figure2. The parent node here is still null value


Figure3. When I expand the parent node, the parent node is displayed normally


Figure4. Expected results
But the UI you see in the user experience should be displayed regardless of whether the parent node is expanded...

  1. When all child nodes are selected, the parent node will be checked (true)
  2. When the child node is partially selected, the parent node will display null
  3. When all child nodes are not selected, the parent node will be displayed as unchecked (false)

Because the current TreeItemRender method seems to obtain the properties and values ​​of child nodes only when the parent node is expanded, but in practice, sometimes there is no need to expand the parent node. Simply checking the parent node can add the values ​​of all child nodes to CheckedValue.

That's why I have more doubts about this. Please forgive me and thank you for your patient help.

I'll try to explain again. The parent node cannot know if there are checked/unchecked children unless they are expanded - before the expansion no children exist. To set the parent node checked state you should use a logic independent of children expansion in ItemRender:

and as you can see the checked state will be the same before and after expanding children:


Got it, sorry, thank you for your explanation!
I understand how to use this component, and I try to write logic through component methods to make this logic work as I want.
I'm really sorry to have you spend so much time explaining. Thank you for your help!