BLOG LIST

C# DataGridView, Slow scrolling and the solution

This is interesting : starting from .Net 2.0 ( the issue didn’t appear on .Net 1.1, and is still here also on .Net 3.5 ) the Microsoft DataGridView Winforms control has become really, really sluggish. I never noticed it, until I had to fill the control with a lot of records, with a reasonable number of columns, and full screen.

What happened is that the scroll is very slow, at the point that you can count the seconds while the grid is drawing. The solution is to enable an hidden feature of DataGridView, that is DoubleBuffered.

Just add System.Reflection to your using list, and the following code, wherever you prefer in you application.

   1:  public static class ExtensionMethods
   2:  {
   3:      public static void DoubleBuffered(this DataGridView dgv, bool setting)
   4:      {
   5:          Type dgvType = dgv.GetType();
   6:          PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
   7:              BindingFlags.Instance | BindingFlags.NonPublic);
   8:          pi.SetValue(dgv, setting, null);
   9:      }
  10:  }

Found this solution here : http://bitmatic.com/csharp/fixing-a-slow-scrolling-datagridview

Blog List
An unhandled exception has occurred. See browser dev tools for details. Reload 🗙