How to improve painting performance of DataGridView?

后端 未结 6 815
别那么骄傲
别那么骄傲 2020-12-01 12:40

(sorry for bad English)

I have a big problem with performance of DataGridView when it re-paints.

I\'m using a DataGridVie

相关标签:
6条回答
  • 2020-12-01 13:02

    Clean Solution without reflection is:

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

    Then go to myForm.designer.cs and change a type from DataGridView to DataGridViewDoubleBuffered .

    0 讨论(0)
  • 2020-12-01 13:07

    i use this solution and saw bit fixed.

    Reflection is used so import this too in code

    using System.Reflection;
    
    typeof(DataGridView).InvokeMember("DoubleBuffered",
    BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty,
    null,this.dataGridView1,new object[] { true });
    
    0 讨论(0)
  • 2020-12-01 13:18

    Also read MSDN article: Best Practices for Scaling the Windows Forms DataGridView Control

    0 讨论(0)
  • 2020-12-01 13:20

    Have you enabled double buffering for the grid view?

    have a look at Horrible redraw performance of the DataGridView on one of my two screens

    if you haven't already for some ideas

    0 讨论(0)
  • 2020-12-01 13:23

    When working with large amounts of data, the DataGridView control can consume a large amount of memory in overhead, unless you use it carefully. On clients with limited memory, you can avoid some of this overhead by avoiding features that have a high memory cost.

    You can also manage some or all of the data maintenance and retrieval tasks yourself using virtual mode in order to customize the memory usage for your scenario. More detail you can visit dapfor. com

    0 讨论(0)
  • 2020-12-01 13:24

    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.

    0 讨论(0)
提交回复
热议问题