I’m working on a certain project in C# and using DataGridView in the project but encounter flickering grid and slow refresh in the DataGridView as the data increases. I usually use SuspendLayout and ResumeLayout to deal with this issue but I’m not contented with the outcome. So I look for the solution for this issue and found this post from Bitmatic showing a simple solution. I posted it here to share to you guys and for me to use these codes as reference for my future C# projects.

using System.Reflection;
//Put this class at the end of the main class or drop it anywhere in your project

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

// Then, enable DoubleBuffered in your code

DataGridView1.DoubleBuffered(true);

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments