RadTreeView Scrolls to the top when new data is added and virtualisation is enabled

0 Answers 31 Views
TreeView
Richard
Top achievements
Rank 1
Richard asked on 09 Dec 2021, 01:44 PM

Hi, 

we have a dataset of several thousand items which needs to be fully expanded if some search criteria is applied. This can be displayed with virtualization enabled but we encounter an issue where if we add new records the scroll position jumps to the top, this is not the case with virtualization disabled. 

we are using a hierarchical data template to display our tree view items , and would like the scroll position to remain somewhat consistently in the same place. 

Thanks, 

Richard 

 

 

 

 

 

Martin Ivanov
Telerik team
commented on 14 Dec 2021, 11:31 AM

Adding a new item to the ItemsSource of RadTreeView should not move the scrollviewer. This said, probably there is some additional code that replaces the ItemsSource or there is an issue with the scrolling that appears in specific situations. I could suggest you to attach a project showing the exact setup, so I can take a look.
Richard
Top achievements
Rank 1
commented on 23 Feb 2022, 01:36 PM

Hi, 

Sorry for the delay, I have attached an example solution (no .exe sorry; issues with firewall)

Example Scenario

--> Expand data

--> Scroll Down

--> Add data

Result:

Scroll position will sometime move.

Our intended use case involves supplying real time (every 10 seconds or so) updates to this treeview, and this issue reduces the usability. 

 

 

 

 

Martin Ivanov
Telerik team
commented on 25 Feb 2022, 11:55 AM

Thank you for the project. The jump happens because you reset the ItemsSource of the RadTreeView control and its child items. This happens on two places in the code. The first one is the RefreshNode() call that raises PropertyChanged for the TreeItems property. And the second one is the call that sets the DataContext of the MainWindow to null and then back to "treeSearch". Both those actions reset the ItemsSource which is redrawning the RadTreeView control. 

To avoid the jump, instead of resetting the ItemsSource, you can just add or remove items from the hierarchy. Note that this cannot happen with the current setup (with the Dictionary and the IValueConverter). To achieve the desired effect, you can use ObservableCollection and hierarchy-based data models. The idea here is that the collections in the hierarchy should implement the INotifyCollectionChanged in order to allow updates in the UI when an item is added or removed. I've updated your project to show one way to do this. I hope that helps.

Note that in the attached project you can still see a behavior that seems like jumping, but this is only if items are added after the current viewport. In this case, the scrollable height changes because you extend the viewport with new items.

No answers yet. Maybe you can help?

Tags
TreeView
Asked by
Richard
Top achievements
Rank 1
Share this question
or