How to prevent DataGridView from flickering |Blinking

How to prevent DataGridView from flickering |Blinking

Added by Sixth Sense updated on Wednesday, March 7, 2018

Problem:

Flickering is common problem in windows forms DataGridView when we use huge data to display. Overcome this problem is tricky part which we will discuss in this small snippet.

By Sub Class:

One possible solution is to use custom control by sub classing and assign DoubleBuffered property to true in constructor as shown below.

public class MyDataGridView : DataGridView
{
	public MyDataGridView()
    {
        DoubleBuffered = true;
    }
}				
				

By Reflection:

Another solution is to make extension method as shown below.

public static void DoubleBuffered(this DataGridView dgv, bool bvalue)
{
	Type dgvType = dgv.GetType();
    PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
    pi.SetValue(dgv, bvalue, null);
}				
				

Usage:

Later on we can use this extension method as shown below.

DataGridView1.DoubleBuffered(true);				
				

To disable double buffering

DataGridView1.DoubleBuffered(false);				
				

About

29 Tutorials
25 Snippets
6 Products

More

Contact Us

Contact us

Stay Connected