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 of 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 extension methods.
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
April 2nd, 2010 at 8:04 pm
Thank you sooooo much!!! I’ve tried every suggestion online and this is the only one that actually works.
April 8th, 2010 at 3:26 pm
Assuming you’ve called the module ExtensionMethods, use the following in your windows form:
Imports ExtensionMethods
‘I put this in the Form Load event…
ExtensionMethods.DoubleBuffered(GridViewName, True)
Hope this helps
April 9th, 2010 at 11:03 pm
Awesome! Thanks! It works great!
I’m updating different styles for 100-200 cells and it was ugly to watch them peel down the DGV. It actually made some of my users perceive that the application was running slowly, assuming that it was a database latency issue.
None of the other suggestions worked, but this did. Now, the DGV quickly and professionally flashes to the re-styled cells.
April 27th, 2010 at 4:00 am
You are a life saver. And also thanks to Michael for posting the Visual Basic version of the code.
It was a freak of chance that led me here, since none of the keywords I was using to seek out an answer to the problem ever led me here.
Your solution is both elegant and powerful.
May 4th, 2010 at 4:38 pm
Cheers from NJ!
May 23rd, 2010 at 8:56 am
amazing, microsoft should include this solution at msdn!!!
June 18th, 2010 at 5:56 am
WOW WOW WOW WOW WOW
YOU ARE AWESOME. THIS IS AN AWESOME SOLUTION.
THANK YOU!!!
June 20th, 2010 at 8:41 am
Thank you very much (:
June 21st, 2010 at 3:30 pm
Great solution. Thx for the VB.NET code. Fixed the slow scrolling.
June 22nd, 2010 at 12:59 pm
Thanks for Double Buffering!
It works better, but .Net DataGridView don’t works like grid at Delphi or result grid at Query Analyzer 2000… I can’t understand why it can works worse.. Maybe problem that .Net FrameWork is slow.
Thanks for code!
August 6th, 2010 at 9:47 am
I’ve had to return
to windows developing after a couple of years away. Microsoft have still got the idea that making everything difficult for developers is a good thing. Start learning Objective C, it’ll only be a few years before Apple show Microsoft how it should be done.
Thanks for the code, works a treat.
August 6th, 2010 at 1:04 pm
Thanks so much: I’ve been looking for something like that for weeks, and finally this is the only way not to see that horrible flickering on my datagridview; a special thx to Michael for the vb code, which is the one I used.
September 22nd, 2010 at 9:09 am
Brilliant and KISS (Keep It Short & Simple).
Cheers
September 25th, 2010 at 8:35 pm
Thanks a lot! Now the original Microsoft’s DataGridView is really usable component.
October 6th, 2010 at 4:36 am
Still not working.. Ive created a module. then calling the method in the form or in the button. Flickering occurs when looping in datagridview.. please help.
November 11th, 2010 at 3:05 am
Thanks so much for this solution. Been looking for ways to fix the terrible painting performance of DataGridView for ages. So much better with it double buffered!
Been through 100 different suggestions, finally found yours which is perfection
November 13th, 2010 at 9:06 am
I’m getting this error before compiling:
Cannot access protected member ‘System.Windows.Forms.Control.DoubleBuffered’ via a qualifier of type ‘System.Windows.Forms.DataGridView’; the qualifier must be of type ‘Tick_Backtest.ClusPro’ (or derived from it)
Is there something I should add to the code?
November 16th, 2010 at 1:13 am
Thks. Worked like a charm.
November 29th, 2010 at 9:06 am
Thanks! Double buffering surely enhanced performance big time. Strange that MS made this a hidden property.
December 10th, 2010 at 7:00 am
Thanks!!!
December 12th, 2010 at 5:32 pm
Thanks very much, after a lot of search on web i got this very simple and the best solution. It improved efficiency of datagridview many folds.
Thanks again
February 22nd, 2011 at 3:33 pm
Awesome fix. Here’s the complete code in VB.net using Michael’s VB code:
‘ add a new module to your project and name in ExtensionMethods.vb
‘ In ExtensionMethods.vb, add the following code
Imports System
Imports System.Reflection
Imports System.Windows.Forms
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
‘ now, for usage in your main form code (e.g. form1.vb) load form event, you can set double-buffering (assuming you DataGridView is called DataGridView1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ExtensionMethods.DoubleBuffered(Me.DataGridView1, True)
End Sub
March 2nd, 2011 at 9:00 pm
THANK YOU SO MUCH! This is what I needed to resolve some grid issues.
For VB.Net
you should import CompilerServices and use the Extension attribute (so it will work like the C# example above).
‘ Sample call
DataGridView1.DoubleBuffered(True)
…
‘ in extension module add these Imports
Imports System.Runtime.CompilerServices
Imports System.Reflection
‘ Then in the module, here is a condensed version of the class
_
Public Sub DoubleBuffered(ByVal dgv As DataGridView, ByVal doubleBuffer As Boolean)
Dim pi As PropertyInfo = dgv.GetType().GetProperty(“DoubleBuffered”, BindingFlags.Instance Or BindingFlags.NonPublic)
pi.SetValue(dgv, doubleBuffer, Nothing)
End Sub
March 2nd, 2011 at 9:02 pm
Ok – the HTML dropped my ATTRIBUTE tag.
Use
‘Except instead of the brackets [ ] use Greater Than, Less Than.
[Extension()] _
Public Sub DoubleBuffered(ByVal dgv As DataGridView, ByVal doubleBuffer As Boolean)
Dim pi As PropertyInfo = dgv.GetType().GetProperty(“DoubleBuffered”, BindingFlags.Instance Or BindingFlags.NonPublic)
pi.SetValue(dgv, doubleBuffer, Nothing)
End Sub
April 15th, 2011 at 1:06 pm
Thank you all so much.. this has made my project about 100 times more usable!!!!
Thanks
June 10th, 2011 at 5:27 pm
YOU ARE MY HERO!!!
July 7th, 2011 at 9:17 pm
Such a quick and simple solution!!!!! I love you!!!!!!!!
August 24th, 2011 at 2:02 pm
typeof(DataGridView).InvokeMember(“DoubleBuffered”, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, my_dgv_ctrl_, new object[] { true });
September 6th, 2011 at 2:23 pm
Thanks a lot… It worked freaking awesome…
Thanking you million times
VIbz
October 15th, 2011 at 8:04 pm
Andrew, your solution is great! Thank you very much!
December 6th, 2011 at 1:14 pm
Andrew,
Thank you very much
You really saved me
good luck
December 15th, 2011 at 10:58 am
Thank you a lot!
Grazie mille!
Riki
December 21st, 2011 at 4:12 pm
AMAZING!!!
February 19th, 2012 at 8:55 am
Thank you
March 31st, 2012 at 5:28 am
Wonderful.
April 13th, 2012 at 1:10 pm
Thanks for your solution using extension methods!
However I found that I had to enable double buffering for all controls in my application, just enabling it for the DataGridView was not sufficient.
What I did was this:
Change your extension method to work on Controls:
public static class ExtensionMethods
{
public static void DoubleBuffered(this Control control, bool setting)
{
Type dgvType = control.GetType();
PropertyInfo pi = dgvType.GetProperty(“DoubleBuffered”, BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(control, setting, null);
}
}
And call it for all controls in my app in the constructor of the main program: DoubleBuffer(this):
protected void DoubleBuffer(Control control)
{
control.DoubleBuffered(true);
foreach (Control c in control.Controls) { DoubleBuffer(c); }
}