Once again I am spending a lot of time working with Telerk’s RadControls for WinForms, and most recently have been looking for all sorts of ways to squeeze every possible bit of speed out of a RadGridView control. Sometimes a really simple change has made a noticeable improvement, and I thought it would be useful to collect those simple-yet-effective tips all in one place.
There are basically two types of datasets that seem to slow down my grids – those with a large number of rows (over 5000) and those with a large number of columns (over 25).
RadGridView controls actually handle many thousands of rows very well. The only time I’ve had trouble is when there are many specially formatted cells with images and lots of scrolling going on. To help in that situation, I’ve found the control performs better if you set EnableFastScrolling to true.
radGridView1.EnableFastScrolling = true;
When this setting is enabled, the grid only moves after you’ve finished scrolling, and so only has to re-draw your special cells once, instead of over and over again as the scroll is happening. There’s also a tooltip that will show up during the scroll to let you know what row you are currently scrolling to.
Note: if your data is more along the lines of hundreds of thousands of rows, you may instead want to look into virtual mode for your grid.
Grids with many columns seem to be more of a problem than rows for the RadGridView, and is also made worse by the use of special columns, like checkbox and custom columns. There’s always the issue of fitting the columns, and when there are more than 50 columns with many thousands of rows, using the BestFit method on the columns does get a bit sluggish. I’ve found it’s faster to use the BestFitColumns method of the MasterGridViewTemplate. If fitting to the data is especially slow, you can also create your columns first, then do the BestFitColumns, and add your data last.
radGridView1.MasterGridViewTemplate.BestFitColumns();
The final simple way to speed up the grid applies to BestFitColumns, and any other operation that will affect many columns or rows of data. Whatever operation you want to call on the grid to change it, make the call between the BeginUpdate and EndUpdate methods of the GridElement.
radGridView1.GridElement.BeginUpdate();
radGridView1.MasterGridViewTemplate.BestFitColumns();
radGridView1.GridElement.EndUpdate();
I found that allowing the user to perform an operation like Delete on multiple rows in a large dataset – say 1000 rows out of 5000, was painfully slow before I added the BeginUpdate and EndUpdate calls. Afterwards, the operation was nearly instant!
List<GridViewRowInfo> selectedrows = radGridView1.SelectedRows.ToList();
radGridView1.GridElement.BeginUpdate();
foreach (GridViewRowInfo gvdri in selectedrows)
radGridView1.Rows.Remove((GridViewDataRowInfo)gvdri);
radGridView1.GridElement.EndUpdate();
The great part about these tips is none of them require any serious changes to your forms, but might make a real difference to your users.
To get more help with Telerik’s RadGridView for Winforms, check out their great support site, or Falafel’s own training classes and consulting services.