Problem with scroll after save and NewRowPosition definition

8 posts, 0 answers
  1. Lynda Golomb
    Lynda Golomb avatar
    40 posts
    Member since:
    Dec 2009

    Posted 12 Sep Link to this post

    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

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 13 Sep Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Lynda Golomb
    Lynda Golomb avatar
    40 posts
    Member since:
    Dec 2009

    Posted 13 Sep in reply to Dilyan Traykov Link to this post

    Thanks, I'll have a look at the project and get back to you.
  5. Lynda Golomb
    Lynda Golomb avatar
    40 posts
    Member since:
    Dec 2009

    Posted 13 Sep in reply to Lynda Golomb Link to this post

    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.

  6. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 14 Sep Link to this post

    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.
  7. Lynda Golomb
    Lynda Golomb avatar
    40 posts
    Member since:
    Dec 2009

    Posted 15 Sep in reply to Dilyan Traykov Link to this post

    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.

  8. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 16 Sep Link to this post

    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.
  9. Lynda Golomb
    Lynda Golomb avatar
    40 posts
    Member since:
    Dec 2009

    Posted 18 Sep in reply to Dilyan Traykov Link to this post

    Thanks very much!! this worked.

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

Back to Top
UI for WPF is Visual Studio 2017 Ready