Click here to Skip to main content
15,175,307 members
Articles / Programming Languages / C#
Posted 23 Oct 2013

Tagged as


10 bookmarked

Double Buffering a DataGridview

Rate me:
Please Sign up or sign in to vote.
4.97/5 (13 votes)
23 Oct 2013CPOL
Two ways to double buffer a DataGridView


Recently, I had a Winforms projects that required me to display data approximately 1000 rows to a DataGridView control. Once added, some logic was applied to each row to determine the color of the row. There was no problem until the user began scrolling through the information. It caused the rows to flicker.

Using the Code

As the DoubleBuffered property of the DataGridView control is hidden, you have to either create a custom class so that you can set the property.

public partial class myDataGridView : DataGridView
    public myDataGridView()
        DoubleBuffered = true;

Or you could invoke the property using the following code snippet below where DataGridViewControlName is the name of your DataGridView control that you are using in your code.

//Set Double buffering on the Grid using reflection and the bindingflags enum.
typeof(DataGridView).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | 
BindingFlags.Instance | BindingFlags.SetProperty, null, 
DataGridViewControlName, new object[] { true });


  • Original version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pin
Sławomir Adamski3-Oct-19 9:39
MemberSławomir Adamski3-Oct-19 9:39 
SuggestionOne suggestion... Pin
Daniel Leykauf17-Mar-14 8:11
MemberDaniel Leykauf17-Mar-14 8:11 
Double buffering is very useful. But if you resize the column you will not see the sizing line correctly.
To prevent this I use the following code to dectect if the cursor is on the column and to set the buffering mode:

On mouse down:
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
    If HitTest(e.X, e.Y).RowIndex = -1 Then SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
End Sub

And on mouse up:
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
    If HitTest(e.X, e.Y).RowIndex = -1 Then SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
End Sub

GeneralRe: One suggestion... Pin
Simon_Whale17-Mar-14 8:14
professionalSimon_Whale17-Mar-14 8:14 
GeneralMy vote of 5 Pin
francovaro22-Jan-14 5:59
Memberfrancovaro22-Jan-14 5:59 
GeneralRe: My vote of 5 Pin
Simon_Whale22-Jan-14 6:04
professionalSimon_Whale22-Jan-14 6:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.