Restoring Grid State after data refresh

6 posts, 1 answers
  1. Mark
    Mark avatar
    32 posts
    Member since:
    Jan 2012

    Posted 04 Jan 2013 Link to this post

    Hi,

    We have a grid with a couple of thousand rows of data, handlers on data change/selection change events, RowFormatting/Cell Formatting events and a number of conditional formatting rules applied.

    We are trying to ensure that the user is placed back on their previously selected row after the grid data is refreshed. At the moment, we are storing the ID of the current row and after a refresh call Grid.TableElement.ScrollToRow to navigate back to the row. There is validation present to ensure that the row is still present.

    The ScrollToRow seems to be performing very slowly though when the selected row is fairly far down the grid and it is difficult to track whether this is caused by a specific event firing for selection change, the formatting events, conditional formatting rules or something else, so I suspect that the ScrollToRow approach is not the ideal solution.

    Is there a better way to navigate back to the previously selected row when the grid is refreshed?

    Thanks,

    Mark.

  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 09 Jan 2013 Link to this post

    Hello Mark,

    In this scenario when the 'ID' of the DataBoundItem is used to find a RadGridView row reference there no any other solution than the ScrollToRow API. You can use the VScrollBar.PossitionOffset property of the TableElement to save / restore the scroll-bar position, but this solution will not work properly in cases when data is changed, sorting or filtering operation is applied.

    If you continue to experience these issues, please send me a sample application with some part of your data so we can review the specific case and try to find the best solution it.

    Thank you for your time and cooperation.

    Regards,
    Julian Benkov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    14 posts
    Member since:
    Aug 2013

    Posted 28 Feb 2014 in reply to Mark Link to this post

    Hi Mark,

    It may not be ideal, but one option to improve the performance of the ScrollToRow call, in your case, might be to wrap the invocation with methods to disable and enable your grid's other events.  The ScrollToRow call should, in theory, be doing nothing more than scrolling to the given row.  The grid should not be introducing any other "side effects" of scrolling; those should be handled explicitly, not accidentally.  How about something like:

    DisableGridEvents();
    try
    {
        grid.ScrollToRow(rowIdx);
    }
    finally
    {
        EnableGridEvents();
    }

    /// DisableGridEvents
    private bool gridEventsEnabled = true;
    private void DisableGridEvents();
    {
        this.gridEventsEnabled = false;
    }

    private void Grid_CellFormatting(...)
    {
        if (this.gridEventsEnabled)
        {
            // do the normal stuff.
        }
    }

    That's incomeplete, but I think you'll get the idea.
  5. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 05 Mar 2014 Link to this post

    Hello,

    Thank you for contacting Telerik Support.

    Suspending the grid events is not a recommended solution because you may encounter a situation in which the CellFormatting will be suspended when it is necessary. Another option is to keep the CurrentRow before refreshing the grid and restore it afterwards, calling the EnsureVisible method as well or restoring the RadGridView.TableElement.VScrollBar.Value.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik

    DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

  6. TIM
    TIM avatar
    4 posts
    Member since:
    Sep 2014

    Posted 21 Jan 2015 in reply to Julian Benkov Link to this post

    Julian,

    You stated that when data is changed, sorting or filter the ScrollToRow API will  not work. Is there any solution you can recommend? It seems if you have such an API there should be a way to accommodate this. 

    I have a similar issue that sorting and filtering make use of the ScrollToRow invalid. 

    Regards
  7. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 26 Jan 2015 Link to this post

    Hello Tim,

    Thank you for writing.

    According to Julian's post, the TableElement.VScrollBar.PossitionOffset property may not restore the scroll-bar position correctly when sorting or filtering operation is applied. The recommended approaches from my previous post behaves as expected on my end. However, note that you may have current row which is not visible in the view as the vertical scroll bar may be scrolled to a certain value. In this situation it would be better to keep and restore the TableElement.VScrollBar.Value. Calling the TableElement.ScrollToRow method place the specific row to be first into the view no matter if the grid is sorted or not.

    If you are still experiencing any difficulties, I would recommend you to open a support thread with a sample project demonstrating the undesired behavior that you are facing. Thus, we would be able to investigate the precise case and assist you further. Thank you in advance.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready