How to improve painting performance of DataGridView?

I recently had some slowness issues with DataGridView and the solution was the following code

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);
}

It turns double buffering on for DataGridView objects. Just call DoubleBuffered() on your DGV. Hope it helps.

Edit: I might’ve gotten this off SO, but I can’t search for the original right now so this is just to emphasize that the code isn’t mine.

Leave a Comment