Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Enable DataGridView DoubleBuffered Property

0.00/5 (No votes)
8 Jul 2016 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here