Click here to Skip to main content
Click here to Skip to main content
Go to top

Double Buffering a DataGridview

, 23 Oct 2013
Rate this:
Please Sign up or sign in to vote.
Two ways to double buffer a DataGridView

Introduction

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()
    {
        InitializeComponent();
        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 });

History

  • Original version

License

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

Share

About the Author

Simon_Whale
Software Developer Oak Underwriting
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
SuggestionOne suggestion... PinmemberDaniel Leykauf17-Mar-14 7:11 
GeneralRe: One suggestion... PinprofessionalSimon_Whale17-Mar-14 7:14 
GeneralMy vote of 5 Pinmemberfrancovaro22-Jan-14 4:59 
GeneralRe: My vote of 5 PinprofessionalSimon_Whale22-Jan-14 5:04 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 23 Oct 2013
Article Copyright 2013 by Simon_Whale
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid