Hello,
The problem is similar to https://feedback.telerik.com/blazor/1552955-child-treeview-items-not-checked-after-expand, but in this case, the TreeView is using load-on-demand and the OnExpand event. As soon as a checked parent is expanded, the child checkboxes are always unchecked.
Here is a test page. Expand the parent item, check it, collapse it and then expand it again. The child nodes will lose their checked state.
<TelerikTreeView Data="@FlatData"
OnExpand="@LoadChildren"
CheckBoxMode="@TreeViewCheckBoxMode.Multiple"
CheckChildren="true"
CheckParents="true"
@bind-CheckedItems="@CheckedItems"
@bind-ExpandedItems="@ExpandedItems">
</TelerikTreeView>
@code {
List<TreeItem> FlatData { get; set; } = new List<TreeItem>();
IEnumerable<object> CheckedItems { get; set; } = new List<object>();
IEnumerable<object> ExpandedItems { get; set; } = new List<object>();
async Task LoadChildren(TreeViewExpandEventArgs args)
{
TreeItem currItem = args.Item as TreeItem;
if (args.Expanded && !FlatData.Any(x => x.ParentId == currItem.Id))
{
if (currItem.Id == 1)
{
FlatData.Add(new TreeItem()
{
Id = 4,
Text = "Child 1 of Parent 1",
ParentId = 1,
HasChildren = false
});
FlatData.Add(new TreeItem()
{
Id = 5,
Text = "Child 2 of Parent 1",
ParentId = 1,
HasChildren = false
});
}
}
}
protected override void OnInitialized()
{
FlatData = LoadFlat();
}
private List<TreeItem> LoadFlat()
{
FlatData.Add(new TreeItem()
{
Id = 1,
Text = "Parent 1",
ParentId = null,
HasChildren = true
});
return FlatData;
}
public class TreeItem
{
public int Id { get; set; }
public string Text { get; set; }
public int? ParentId { get; set; }
public bool HasChildren { get; set; }
}
}