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

SfDataGrid - ScrollToRowIndex

Thread ID:





129793 Apr 4,2017 06:27 AM UTC Apr 13,2017 06:21 AM UTC Xamarin.Android 5
Tags: SfDataGrid
Asked On April 4, 2017 06:27 AM UTC

I have problem with sfDataGrid scrolling to row index after screen changes orientation. When you put sfDataGrid.ScrollToRowIndex into the button's Click, it's ok, but I want to scroll to selected row index after screen rotation. Then I get System.NullReferenceException, but nothing is null! I set breakpoint and saw that sfDataGrid has ItemsSource and selectedGridRow (as being int can't be null) has the value that it should. My code:

         public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            if (savedInstanceState != null)
                selectedGridRow = savedInstanceState.GetInt("selectedGridRow");
            sfDataGrid.SelectedIndex = selectedGridRow;

            return view;

Thanks in advance.

Replied On April 4, 2017 08:07 AM UTC

I solved it by putting sfDataGrid.ScrollToRowIndex(sfDataGrid.SelectedIndex) into sfDataGrid.GridLoaded event, but in my opinion it is "going around" solution.

Pavithra  Sivakumar [Syncfusion]
Replied On April 6, 2017 03:53 AM UTC

Hi Stanicb, 
Thanks for contacting Sycfusion support. 
We have checked your query and we are not able to reproduce the reported Scrolling issue while changing orientation in our SfDataGrid. For your reference we have attached our tested sample in the below sample location. Could you please share more details regarding your requirement, otherwise please revert us by modifying the attached sample based on your requirement, that would be more helpful for further analyze.  
Pavithra S 

Replied On April 6, 2017 06:29 AM UTC

As I said in my first post on this page, problem is when the ScrollToRowIndex is in public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){...}.
As I said in my second post on this page, I have also solved it in sfDataGrid.GridLoaded event.

But actually that is not a problem, because it works. The new problem is scrolling to row index when I have groups (by GroupColumnDescription) or SummaryRow. If I click on the first item in first group, after rotating selection is on the second item. If I click on the first item in second group, after rotating selection is on the third item of the second group, if I click the last item in the first group, selection is on the first item of the second group, and so on... In each group, selection is moved for the count of previous groups. It means that indexes has been created twice: first without groups and then recreated with groups.
Before rotation:

After rotation:

I still need help on this matter. Thanks in advance.

Divakar Subramaniam [Syncfusion]
Replied On April 12, 2017 06:26 PM UTC

Hi Stanicb, 
Thanks for the provided details. 
We have checked the reported query and we were able to reproduce the reported issue on our side. However, the issue has been reproduced only if use the index get from the old instance(say Bundle). If we set DataGrid.SelectedIndex as some value(as hardcore), then the selection is maintained properly in the provided index even after the screen rotation. So, we suspect that most probably the issue will be in the old instance we have stored and not in SfDataGrid. However, we are currently analyzing the issue on our side and we will provide the further details regarding the issue on or before 17/04/2017. 
We appreciate your patience until then. 

Divakar Subramaniam [Syncfusion]
Replied On April 13, 2017 06:21 AM UTC

Hi Stanicb, 
We have resolved your query in sample level. Instead of storing only the DataGrid.SelectedIndex value from the previous instance, store the whole SfDataGrid instance and use it when the screen rotates. Please refer the below code snippet for better understand. 
//Local variable to store the datagrid instance 
static object value; 
protected override void OnCreate(Bundle bundle) 
    if (dataGrid == null) 
        if (value != null) 
            dataGrid = value as SfDataGrid; 
            dataGrid = new SfDataGrid(BaseContext); 
            dataGrid.ItemsSource = viewModel.OrdersInfo; 
            dataGrid.AutoGenerateColumns = true; 
            dataGrid.SelectionMode = SelectionMode.Single; 
            dataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "CustomerID" }); 
protected override void OnPause() 
    //Store the old instance of SfDataGrid whenever the screen rotates. 
    value = dataGrid; 
Whenever the screen rotates, OnPause() override will hit. So, you can store the old instance of the SfDataGrid there and use it wherever needs. We have prepared a simple sample for your reference and you can download the same from the below link. 


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

or the page will be automatically redirected to 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