This is a migrated thread and some comments may be shown as answers.

Problem with scroll after save and NewRowPosition definition

7 Answers 70 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lynda Golomb
Top achievements
Rank 1
Lynda Golomb asked on 12 Sep 2016, 08:43 AM

Hi,

RadGridView behavior after update/insert row is different between NewRowPosition="Top" and NewRowPosition="Bottom".
When position is defined "top", after saving the scroll is on the same position as before saving. However, when the position is defined "Bottom", after saving it scrolls to top.
Workaround with ScrollIntoView() is not useful in my case, because I may have many rows updated.
How can I achieve the same behaviour as NewRowPosition="Top" after saving?

Thanks

7 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 13 Sep 2016, 12:44 PM
Hello Lynda,

I tried to reproduce the behavior you've described, but was, unfortunately, unable to do so. In both cases, when I add or edit a row, the scroll offset does not change.

Could you please have a look at the attached project and let me know whether I'm missing something important? If that is the case, please provide more details on the exact steps needed to reproduce this behavior.

Thank you in advance for your cooperation on the matter.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Lynda Golomb
Top achievements
Rank 1
answered on 13 Sep 2016, 12:48 PM
Thanks, I'll have a look at the project and get back to you.
0
Lynda Golomb
Top achievements
Rank 1
answered on 13 Sep 2016, 02:59 PM

Hi, I've been able to reproduce the problem, please find project attached.

Change the following:

1. In MyViewModel add:

public QueryableCollectionView GridRows { get; set; } //Instead of Clubs

2. Add constructor in MyViewModel

public MyViewModel()
        {
            GridRows = new QueryableCollectionView(Clubs);
        }

3. Add function in MyViewModel

public void AddClubs()
        {
            //Add Or Update 
           GridRows.Refresh(); 
        }

5. In MainWindow.xaml in clubsGrid change to:

ItemsSource="{Binding GridRows}"

6. In MainWindow code behind:

private void Button1_Click(object sender, RoutedEventArgs e)
        {
            var parent = clubsGrid.DataContext as MyViewModel;
            if(parent == null ) return;

           parent.AddClubs();
        }

Scenario :
1) Update any row in grid (in the middle of a grid).
2) Click "Save". The scroll moves to top.
When NewRowPosition="Top" it does not happen.

0
Dilyan Traykov
Telerik team
answered on 14 Sep 2016, 08:21 AM
Hello Lynda,

Is there any reason you're calling the QueryableCollectionView's Refresh method? From what I observe, simply modifying/adding objects to the bound ObservableCollection will result in the desired result - no scrolling is done, but RadGridView is still notified about the changes made.

public void AddClubs()
{
    this.Clubs[0].Name = "asdf";
    this.Clubs.Insert(0, new Club() { Name = "Tottenham" });;
}

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Lynda Golomb
Top achievements
Rank 1
answered on 15 Sep 2016, 06:15 AM

Hi,

The reason we use the Refresh function is because of another issue that happens when a combobox is integrated within the grid.

As said earlier this works perfectly well when NewRowPosition="Top" and not NewRowPosition="Bottom".

We need this to work in the same way.

Thanks.

0
Dilyan Traykov
Telerik team
answered on 16 Sep 2016, 12:02 PM
Hello Lynda,

This undesired behavior can be avoided by adding the following lines before and after the AddClubs method:

var scrollViewer = this.clubsGrid.FindChildByType<GridViewScrollViewer>();
var startOffset = scrollViewer.VerticalOffset;
 
parent.AddClubs();
 
scrollViewer.ScrollToVerticalOffset(startOffset);

Please let me know if this would work for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Lynda Golomb
Top achievements
Rank 1
answered on 18 Sep 2016, 09:31 AM

Thanks very much!! this worked.

However, I still think this should be resolved instead of such a workaround  :-)

Tags
GridView
Asked by
Lynda Golomb
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Lynda Golomb
Top achievements
Rank 1
Share this question
or