Fixing a slow scrolling DataGridView
Whenever your C#/.NET DataGridView reaches a certain size, it tends to get really slow to scroll. Depending on the speed of your computer this may be more or less noticeable. In an application i did for a client this became a real problem due to a combination af lots of DataGridView cells and fairly slow computers.
Luckily the solution turned out to be simple…
Turn on double buffering
Turning on double buffering seems to solve the problem. Normally double buffering would only help reduce flickering, since painting is being done to an off-screen buffer, but for the DataGridView it also significantly reduces the amount of functions being called internally in the DataGridView – thus reducing processor load and increasing speed. (statistics gathered with the Eqatec Tracer)
My DataGridView doesn’t have a DoubleBuffered property !?!?
For some reason Microsoft has decided to hide the DoubleBuffered property from DataGridView. Luckily you can set it anyway with reflection.
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); } }
Just drop the above class into your project somewhere, or add the function to your existing extensionmethods.
The extension method allows you to set the DoubleBuffered property on your DataGridView in the following manner:
dataGridView1.DoubleBuffered(true);
You now have a smooth scrolling DataGridView

November 2nd, 2009 at 6:38 pm
Wow! I’ve just tried this and it works amazingly!!! I was in despair because all my datagridviews where so slow. This definitely fix the problem. Thanks
November 10th, 2009 at 7:35 am
After going through the usual “fixes” and workarounds found on the ‘Net for slow DataGridView, this is the first one that makes a substantial difference. The other ones make small or no improvements but this one genuinely fixes the repainting slowdown for me. Thanks.
November 10th, 2009 at 7:38 am
PS. Please make sure your code includes the line:
using System.Reflection;
November 10th, 2009 at 8:48 am
Thanks for the reminder Amber
The full list of namespaces required for the function to compile is:
using System;
using System.Reflection;
using System.Windows.Forms;
December 25th, 2009 at 8:12 pm
Thanx a lot, it helps me to get rid off the slowly scrolling dgv. ^_^
December 31st, 2009 at 5:17 am
Just found this very helpful solution, works a treat, Cheers! Saved me from subclassing a bunch of grids.
For anyone needing this in VB.Net:
‘Code Below
Imports System
Imports System.Reflection
Imports System.Windows.Forms
Public Module ExtensionMethods
_
Public Sub DoubleBuffered(ByVal dgv As DataGridView, ByVal setting As Boolean)
Dim dgvType As Type = dgv.[GetType]()
Dim pi As PropertyInfo = dgvType.GetProperty(“DoubleBuffered”, BindingFlags.Instance Or BindingFlags.NonPublic)
pi.SetValue(dgv, setting, Nothing)
End Sub
End Module
‘End Code
February 19th, 2010 at 4:12 pm
Hi ! Can you post a sample im vb.net ? I am using vb2008 express and i get this error when i try to use your code:
Error 1 Property access must assign to the property or use its value.
I am trying to call it using:
DoubleBuffered(DataGridView1, True)
Thank’s on advance