Click here to Skip to main content
14,238,683 members

Enable DataGridView DoubleBuffered Property

Rate this:
4.92 (5 votes)
Please Sign up or sign in to vote.
4.92 (5 votes)
8 Jul 2016CPOL
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.

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.

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)

Share

About the Author

GhostHost
Software Developer
Italy Italy
No Biography provided

Comments and Discussions

 
Questiondo we have a C# version? Pin
Southmountain12-Jan-18 12:13
memberSouthmountain12-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.

Tip/Trick
Posted 8 Jul 2016

Tagged as

Stats

10.6K views
2 bookmarked