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.
Unfortunately, activation email could not send to your email. Please try again.

Vertical scroll not reset when items are cleared from the grid

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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.
https://www.syncfusion.com/forums/121515/scroll-the-selected-item-into-view
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 09:39 AM

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. 
Regards, 
Jai Ganesh S 


Somanna Chottekalapanda
Replied On December 13, 2016 10:47 AM

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 05:51 AM

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 08:41 AM

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 
 
Regards, 
Jai Ganesh S 


CONFIRMATION

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.

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.

;