We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to improve repaint performance when inserting row in virtual grid (2.0.5.0)

To implement inserting a row in the virtual grid mode I first insert the row in the data source and then repaint the grid. Say, my inserted row index is 5. It seems I need to call grid.InvalidateRange( GridRangeInfo.Rows( 5, grid.ViewLayout.VisibleCellsRange.Bottom + 1 ) ) to show the new row as well as shift ''old'' rows down. The grid is sending query cell info for all the rows in that range. Calling RefreshRange seems to do the same thing. This may affect performance in the case the grid is being dynamically updated at a high rate. It seems what the grid really needs to do is just to repaint the ''old'' rows one row down say, using a double buffered image. Is there a way to optimize the above sample?

6 Replies

AD Administrator Syncfusion Team July 23, 2004 10:50 AM

Instead of repainting from the row down to the bottom of the grid, you can use WindowScroll to scroll the display down a row from that insertion point. Then you can just repaint the single row. The grid has a property that does this when you use calls to grid.Cols.InsertRange to insert the row. You set grid.OptimizeInsertRemoveCells = true; to enable this behavior. But the problem is that you cannot use InsertRange in a viretual grid. But if you set this property, you can trigger the same events by explicilty calling grid.Rows.OnRangeInserted. You have to create the event arg to reflect the rows you are inserting. Alternatively, if you want to directly do the WindowScroll, here is a button handler that will insert a new row at row 1, and then WindowScroll every thing else below it. You could modify this code to handle an arbitrary row position being inserted.
private int counter = 0;
private void button1_Click(object sender, System.EventArgs e)
{
	Console.WriteLine("ClickStart " + counter.ToString());
	int heightToScroll = this.gridControl1.RowHeights[1];
	Rectangle scrollRect =  this.gridControl1.ViewLayout.RectangleBottomOfRow(
	gridControl1.Rows.FrozenCount+1);

	//insert the row...
	this.data.Insert(0, NewRow());
	//scroll the window
	this.gridControl1.ScrollWindow(0, heightToScroll, scrollRect, scrollRect, true);
	//refresh the new row...

this.gridControl1.RefreshRange(GridRangeInfo.Row(1), GridRangeOptions.None);
	//refresh the col headers... (if needed) normally these would not be processed by your QCI
	this.gridControl1.RefreshRange(GridRangeInfo.Col(0), GridRangeOptions.None);
	Console.WriteLine("ClickEnd " + (counter++).ToString());
}


AD Administrator Syncfusion Team July 26, 2004 12:04 AM

Clay, thanks I used the OnRangeInserted - works fine. But the problem is the scrollable view/vertical scroll bar do not seem to update; after inserting a few rows I cannot scroll all the way to view last rows. Is there a cure to this?


AD Administrator Syncfusion Team July 26, 2004 12:39 AM

Try calling grid.UpdateScrollBars.


AD Administrator Syncfusion Team July 26, 2004 07:10 AM

I had. It did not help.


AD Administrator Syncfusion Team July 26, 2004 08:09 AM

Also try calling grid.ResetVolatileData. grid.Refresh calls these methods to handle things in addition to teh baseclass call that triggers the actual painting of the control. So, if grid.Refresh works, you could add these calls one at the time to see what is missing in your case. Model.ResetVolatileData(); ViewLayout.Reset(); CurrentCell.Refresh(); UpdateScrollBars();


MI Mike July 29, 2004 07:47 AM

CAlling ViewLayout.Reset(); did it. Thanks

Loader.
Live Chat Icon For mobile
Up arrow icon