Search code examples
c#performancedatagridview

Slow performance in populating DataGridView with large data


I am using a BindingSource control (reference here) to populate my DataGridView control. There are around 1000+ records populating on it. I am using threading to do so. The DataGridView performs very slow in this case.

I tried to set DoubleBuffered property to true, RowHeadersWidthSizeMode to disabled, AutoSizeColumnsMode to none. But still the same behavior.

How can I improve the performance of the Grid?


Solution

  • If you have a huge amount of rows, like 10,000 and more, to avoid performance leaks - do the following before data binding:

    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing; 
    // or even better, use .DisableResizing. Most time consuming enum is DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
    
    // set it to false if not needed
    dataGridView1.RowHeadersVisible = false;
    

    After the data is bound, you may re-enable it.