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

Grid scrolling to top using DeferRefresh

3 Answers 328 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jerome Prunera-Usach
Top achievements
Rank 1
Jerome Prunera-Usach asked on 19 Nov 2010, 06:46 PM

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

3 Answers, 1 is accepted

Sort by
0
Jerome Prunera-Usach
Top achievements
Rank 1
answered on 19 Nov 2010, 08:06 PM
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.
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 20 Nov 2010, 12:48 AM
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
0
Jerome Prunera-Usach
Top achievements
Rank 1
answered on 22 Nov 2010, 02:54 PM
Thank you for your input, I did mark your reply as answer.
Tags
GridView
Asked by
Jerome Prunera-Usach
Top achievements
Rank 1
Answers by
Jerome Prunera-Usach
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or