We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Vertical scroll not reset when items are cleared from the grid

Thread ID:





127795 Dec 9,2016 08:59 AM UTC Dec 14,2016 01:41 PM UTC WPF 4
Tags: SfDataGrid
Somanna Chottekalapanda
Asked On December 9, 2016 08:59 AM UTC

Hi, The position of the vertical scroll bar in the SfDataGrid does not get reset when the items in the grid are cleared. So when we clear the collection in the view model and add new set of items, the position of the vertical scroll appears whereever it was before. I would like that to be set to the top. 
One suggested solution is in the below link.
However, it gets messy when the grids have filters set and could hide the selected item.

Jai Ganesh S [Syncfusion]
Replied On December 13, 2016 02:39 PM UTC

Hi Somanna, 
We have analyzed your query. We have prepared a sample to achieve your requirement by using the below code.  
private void Button_Click(object sender, RoutedEventArgs e) 
    ObservableCollection<OrderInfo> orders = new ObservableCollection<OrderInfo>(); 
    for (int i = 0; i < 10; i++) 
        orders.Add(new OrderInfo(1001, "James", "Beverton", "ALFKI", "US")); 
        orders.Add(new OrderInfo(1002, "Oliver", "Oregon", "ANATR", "us")); 
        orders.Add(new OrderInfo(1003, "Brendon", "Johanesberg", "ANTON", "China")); 
        orders.Add(new OrderInfo(1004, "John", "Chicago", "YHGTR", "UK")); 
        orders.Add(new OrderInfo(1005, "Charles", "Spain", "BERGS", "China")); 
    this.datagrid.ItemsSource = null; 
    this.datagrid.ItemsSource = orders; 
    this.datagrid.ScrollInView(new RowColumnIndex(1, 0)); 
In the above sample, Filtering also working fine in our side. Could you please share more details or if possible please modify the sample if you got any issue. 
Jai Ganesh S 

Somanna Chottekalapanda
Replied On December 13, 2016 03:47 PM UTC

Thanks for the solution. The problem is, in my case the items are added into an observable collection in the view model. 

Somanna Chottekalapanda
Replied On December 14, 2016 10:51 AM UTC

We can do away with below line and the scroll will still get set to the top of the grid.
this.datagrid.ScrollInView(new RowColumnIndex(1, 0)); 

Its the line setting the item source doing the trick. We don't need to call the ScrollInView. However, not setting this to null before setting the new item source will not reset the scroll position.
And not setting to null before setting item source followed by call to ScrollInView does not reset the scroll position. 
this.datagrid.ItemsSource = null; 

Jai Ganesh S [Syncfusion]
Replied On December 14, 2016 01:41 PM UTC

Hi Somanna, 
A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates 
Jai Ganesh S 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon