C# DataGridView, slow scrolling and the solution
This is interesting: starting from .NET 2.0 (the issue did not appear on .NET 1.1, and is still there on .NET 3.5) the Microsoft WinForms DataGridView control has become really, really sluggish. I never noticed it until I had to fill the control with a lot of records, with a reasonable number of columns, at full screen.
What happens is that scrolling is very slow, to the point that you can count the seconds while the grid is drawing. The solution is to enable a hidden feature of DataGridView: double buffering.
Just add System.Reflection to your using list, and the following extension method wherever you prefer in your application:
public static class ExtensionMethods
{
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
}
Then call it once on each grid, for example in the form constructor:
myDataGridView.DoubleBuffered(true);
Scrolling becomes instantaneous. I found this solution at bitmatic.com.