Radzen Tree Problems Parent Child Checked Values

<RadzenTree AllowCheckParents="true" AllowCheckBoxes="true" @bind-CheckedValues=@CheckedValues Data=@_allPermissions ItemRender="@TreeItemRender">
    <RadzenTreeLevel TextProperty="Name" HasChildren="@(i => ((GtmsModuleDTO)i).ModuleGroups?.Any() ?? false)" ChildrenProperty="ModuleGroups" />
    <RadzenTreeLevel TextProperty="Name" HasChildren="@(i => ((GtmsModuleGroupDTO)i).ModuleSubgroups?.Any() ?? false)" ChildrenProperty="ModuleSubgroups" />
    <RadzenTreeLevel TextProperty="Name" HasChildren="@(i => ((GtmsModuleSubgroupDTO)i).FormTypes?.Any() ?? false)" ChildrenProperty="FormTypes" />
    <RadzenTreeLevel TextProperty="Name" HasChildren="@(i => ((GtmsFormTypeDTO)i).UiControls?.Any() ?? false)" ChildrenProperty="UiControls" />
    <RadzenTreeLevel TextProperty="Name" HasChildren="@(i => false)" />
</RadzenTree>

I have the RadzenTree with more than one hierarchy level. I want to set the "CheckedValues" property of the tree.

checkedValues = GetSelectedValues(_allPermissions);
private List<object> GetSelectedValues(IEnumerable<GtmsModuleDTO> permissions) {
    var selectedValues = new List<object>();
    foreach (var module in permissions) {
        if (module.ModuleGroups != null) {
            foreach (var group in module.ModuleGroups) {
                if (group.ModuleSubgroups != null) {
                    foreach (var subgroup in group.ModuleSubgroups) {
                        if (subgroup.FormTypes != null) {
                            foreach (var formType in subgroup.FormTypes) {
                                if (formType != null) {
                                    if (formType.UiControls != null) {
                                        foreach (var uiControl in formType.UiControls) {
                                            if (uiControl.Id == 2) {
                                                selectedValues.Add(uiControl);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return selectedValues;
}

This is my logic where i am trying to set checkedValues. I have tried many solutions but i cant check the parents of the children. If i am checking for example the formType after adding uiControl to selectedValues, every uiControl is selected, because the object FormType has a List of all UiControls, but i need only to check the uiControl with Id = 2. Can you help me with a solution?

Thanks in advance