Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Enable DataGridView DoubleBuffered Property

Rate me:
Please Sign up or sign in to vote.
4.92/5 (8 votes)
8 Jul 2016CPOL 27.9K   4   6
Increase DataGridView performance

Introduction

When a DataGridView use a big size of data, it tends to get really slow to scroll and it could became problem.

Using the code

Microsoft has decided to hide the DoubleBuffered property, but you can set it anyway with reflection.

VB.NET
Imports System.Reflection

Usually double buffering helps only to reduce flickering, but for the DataGridView it also significantly reduces the amount of functions being called internally in the DataGridView.

VB.NET
Public Sub EnableDoubleBuffered(ByVal dgv As DataGridView)

    Dim dgvType As Type = dgv.[GetType]()

    Dim pi As PropertyInfo = dgvType.GetProperty("DoubleBuffered", _
                                                 BindingFlags.Instance Or BindingFlags.NonPublic)

    pi.SetValue(dgv, True, Nothing)

End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    EnableDoubleBuffered(MyDataGridView, True)

End Sub

License

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


Written By
Software Developer
Italy Italy
I'm a software engineer, specializing in backend development and distributed systems. I have extensive experience in designing and implementing resilient, responsive, scalable, and maintainable systems using C#, .NET on top of cutting-edge technologies.

Comments and Discussions

 
SuggestionDoubleBuffered is not constrained to DataGridView Pin
Daniele Rota Nodari15-Mar-24 1:23
Daniele Rota Nodari15-Mar-24 1:23 
QuestionAmazing speed inc! Pin
LightTempler16-Jan-23 7:16
LightTempler16-Jan-23 7:16 
Thank you!
LiTe

GeneralEnable DataGridView DoubleBuffered Property Pin
AHMAD Shokry 202214-Nov-22 6:54
AHMAD Shokry 202214-Nov-22 6:54 
SuggestionSolo es necesario un parametro Pin
Maximiliano Ledesma22-Jun-20 20:21
Maximiliano Ledesma22-Jun-20 20:21 
QuestionAm I missing something? Pin
Darren Harvey18-Jul-19 22:21
Darren Harvey18-Jul-19 22:21 
Questiondo we have a C# version? Pin
Southmountain12-Jan-18 12:13
Southmountain12-Jan-18 12:13 

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.