Grid scrolling to top using DeferRefresh

4 posts, 1 answers
  1. Jerome Prunera-Usach
    Jerome Prunera-Usach avatar
    12 posts
    Member since:
    Oct 2009

    Posted 19 Nov 2010 Link to this post

    Hello,

    I have a hierarchical grid with about 8000 rows. Based on user interaction I have to update values of specific cell, which I do by looping through the selected rows. There is a conditional formatting on the specific cell which changes the background depending on the value.

    My problem is the following ; if I use the following statement it takes too long :

    foreach (GridViewRowInfo row in this.radGridView1.SelectedRows)
    {
        row.Cells["MY_CELL"].Value = "newValue";
    }

    Now if I use DeferRefresh() the speed is drastically improved, but the grid scrolls back all the way to the top when it is done :

    using (this.radGridView1.DeferRefresh())
    {
        foreach (GridViewRowInfo row in this.radGridView1.SelectedRows)
        {
            row.Cells["MY_CELL"].Value = "newValue";
        }
    }

    I don't know if it is normal behavior, or if there is a way to avoid scrolling back all the way to the top AND keeping the same run time I have with DeferRefresh().

    EDIT : I also tried using BeginUpdate() and EndUpdate() which result in the same scrolling behavior.

    Thank you for your help !

    • OS Information : Windows XP x64 (version 2003) SP2
    • Telerik : RadControls for WinForms 2010.3 10.1109
    • Microsoft Visual Studio 2008
    • .NET 3.5
  2. Jerome Prunera-Usach
    Jerome Prunera-Usach avatar
    12 posts
    Member since:
    Oct 2009

    Posted 19 Nov 2010 Link to this post

    UPDATE : I was able to somewhat maintain the same rows on screen when calling DeferRefresh() by using VisualRows collection.
    It is however only a patch on a wooden leg as behind the scene the grid still scrolls back to the top, and it doesn't work very well when rows are partially shown; the user will still see a movement on the grid.

    // 0 being the header row, the first visible data row is 1
    int index = this.radGridView1.TableElement.VisualRows[1].RowInfo.Index; 
      
    using (this.radGridView1.DeferRefresh()) 
        foreach (GridViewRowInfo row in this.radGridView1.SelectedRows) 
        
            row.Cells["MY_CELL"].Value = "newValue"
        
    }
    this.radGridView1.Rows[index].EnsureVisible();

    Also note that, because this is a hierarchical grid, it will only work with "root parent" (level 1) items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 19 Nov 2010 Link to this post

    Hello Jerome,

    Sadly I've been experiencing the same issues, but this is because whenever you are wrapping your updates with either DeferRefresh() or BeginUpdate() / EndUpdate(true) (here true is for notifying the grid after the update is complete, in order to update values) the grid has to reload all the data, so a very easy fix to your problem would be to just call an ensure visible to the CurrentRow, like so:
    foreach (GridViewRowInfo row in this.radGridView1.SelectedRows)
    {
        row.Cells["MY_CELL"].Value = "newValue";
     
    radGridView1.CurrentRow.EnsureVisible();

    This will always scroll the grid to the CurrentRow, so you won't have problems with hierarchy.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
    Telerik WinForms MVP
  5. Jerome Prunera-Usach
    Jerome Prunera-Usach avatar
    12 posts
    Member since:
    Oct 2009

    Posted 22 Nov 2010 Link to this post

    Thank you for your input, I did mark your reply as answer.
Back to Top