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.

SfDataGrid - ScrollToRowIndex

Thread ID:

Created:

Updated:

Platform:

Replies:

129793 Apr 4,2017 02:27 AM Apr 13,2017 02:21 AM Xamarin.Android 5
loading
Tags: SfDataGrid
stanicb
Asked On April 4, 2017 02:27 AM

Hello,
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;
            sfDataGrid.ScrollToRowIndex(selectedGridRow);

            return view;

Thanks in advance.

stanicb
Replied On April 4, 2017 04:07 AM

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 5, 2017 11:53 PM

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


stanicb
Replied On April 6, 2017 02:29 AM

Hello,
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 02:26 PM

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. 
 
 
Regards, 
Divakar. 


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

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) 
{ 
    base.OnCreate(bundle); 
    if (dataGrid == null) 
    { 
        if (value != null) 
            dataGrid = value as SfDataGrid; 
        else 
        { 
            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() 
{ 
    base.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. 
 
 
 
Regards, 
Divakar. 


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.

;