Set TreeListView.SelectetItem is too slow when subtree init dynamically using GetChildren override

Grids for WPF Forum

The latest build of this product (v2019.1 build 0685) was released 4 months ago, which was before this thread was created.
Posted 5 days ago by Vadim Tsedrik
Version: 19.1.0683
Platform: .NET 4.8
Environment: Windows 10 (64-bit)

Hello, currently we are using in our product TreeListView for WPF and we have big problem when navigating through huge tree.
Our test case contains about 5000 nodes with maximum 6 nesting depth.

Tree looks like:

group B,C,D can contains 1000 nodes in each subgroup. Indexes created dynamically when navigating by tree, and depends on metadata of each variable.

Also class VariableTreeListBoxItemAdapter : TreeListBoxItemAdapter is using for better performance, with override

public override IEnumerable GetChildren(TreeListBox ownerControl, object item)
    var model = item as VarsTreeItem;
    return model != null ? model.Children : null
public ObservableCollection<VarsTreeItemBase> Children
   if (_children == null)
      if (VarMetadata != null)
     return _children;
The  actual problem that binding to SelectedItem in TreeListView from AutoCompleteBox calls GetChildren() from VariableTreeListBoxItemAdapter for all 5000 nodes that created before selected if try to select last node in tree from AutoCompleteBox collection. And this call takes more than 50 seconds in UI thread. If node selected from first group the delay is not so big, and not visible by user.

VarsTreeItemBase.Children property used lazy loading and created elements only for groups and subgroups. Subtree for any variable created in Children property. So when user try to expand elements subtree creates dynamically and fast.
But when user select last item or in the middle of tree from AutoCompleteBox creating of 5000 previous elements in tree is too slow and hangs UI thread using TreeListBoxItemAdapter.
Could you suggest how i can fix the issue?

[Modified 5 days ago]

Comments (3)

Posted 4 days ago by Actipro Software Support - Cleveland, OH, USA


One optimization you can do in your item adapter is override the CanHaveChildren method and return false for any nodes you quickly know for a fact will always be leaf nodes.  When that method returns false, it won't call GetChildren on for that node.

Pair that with setting the item adapter's ChildrenQueryModeDefault property to TreeItemChildrenQueryMode.OnExpansion instead of OnDisplay.  This tells the control to always show an expander and not call GetChildren until the expander is actually clicked.  When this property is its default of OnDisplay, the GetChildren method will be called for each node so that it knows whether to show an expander or not, which is causing the slowdown for you since all the visible nodes above the selection are being examined.  Changing it to OnExpand prevents that slowdown.

If you want more precise control over the TreeItemChildrenQueryMode result for each node, you can override the item adapter's GetChildrenQueryMode method.  It returns the ChildrenQueryModeDefault property value by default.

Actipro Software Support

Posted 4 days ago by Vadim Tsedrik

Hello, thank you for quick feedback.

I tried both suggestions from you: in override CanHaveChildren and return false for definitely leaf node, also set TreeItemChildrenQueryMode.OnExpansion but it still doesn't help me if try to select variable in last group in case of previous groups contains nodes with a lot of Children.
You can see in image that 2nd and 3rd groups contains nodes that can have up to 20000 leafs. And when i try to search variable in 3rd or 4th group it takes me 40seconds to create all nodes for 1st,2nd,3rd groups that not needed for me now.

2nd group example:

search result from AutoCompleteBox

Maybe you can suggest how to change TreeListBoxItemAdapter to call GetChildren only inside search subtree? e.g. GroupD->SubgroupD->Variables and do not call for all other subgroups (GroupA, GroupB, GroupC)

Thank you

[Modified 4 days ago]

Posted 3 days ago by Actipro Software Support - Cleveland, OH, USA


Can you please put together a new simple sample project that shows this delay so that we can work with that and debug your situation to get you a solution?

When you have that ready, send it to our support address (or reply to the other ticket you originally created in the support system with it).  Make sure exclude the bin/obj folders from the ZIP you send so it doesn't get spam blocked.  Thanks!

Actipro Software Support

Add Comment

Please log in to a validated account to post comments.