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.
August 23rd, 2010 at 11:18 pm
Finally, I found the information I was searching for. I have been doing research on this subject, and for three days I keep finding websites that are supposed to have what I’m searching for, only to be discouraged with the lack of what I needed. I wish I would have located your web-site quicker! I had about 40% of what I needed and your site has that, and the rest of what I need to finish my research. Thank you and keep up the good work!