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. Image for the cookie policy date
close icon

Vertical scroll not reset when items are cleared from the grid

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.

4 Replies

JG Jai Ganesh S Syncfusion Team 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 

SC Somanna Chottekalapanda 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. 

SC Somanna Chottekalapanda 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; 

JG Jai Ganesh S Syncfusion Team 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 

Live Chat Icon For mobile
Up arrow icon