Code Optimization

Interesting things in software development and code optimization

DataGridView and huge amount of data rows

Hello my friends,

Did you have a need to populate the DataGridView control with a lot of data? I'm sure you did have.

If you have a huge amount of rows, like 10 000 and more, you will see a huge problem in performance.

To avoid performance leak - you need to set proper value into the RowHeadersWidthSizeMode property.

So the best way is to disable auto resizing during data binding:

dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

you actually can set EnableResizing but avoid to use the DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders

The AutoSizeToAllHeaders is most time consumable parameter.

In addition would be better to set the RowHeadersVisible to false

dataGridView1.RowHeadersVisible = false;

Now you can bind data source, and enable it all or set what you want it to be 

Thank you, see you next time.