Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow performance in populating DataGridView with large data

Tags:

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.

Please assist me in this. How can I improve the performance of the Grid.

Thanks in advance,
Vijay

like image 618
Vijay Balkawade Avatar asked Apr 19 '12 11:04

Vijay Balkawade


People also ask

How can I speed up my DataGridView?

DataGridView works much faster if you prepare an array of rows and "feed" them to the AddRange() method of the Rows collection. Thus, a better version of our code could look like the following one: dataGridView1.

How many rows can DataGridView handle?

Max value, i.e. 2,147,483,647. The DataGridView's RowCount cannot hold a number more than this because it's an integer. So, you can possibly say that limit for datagridview rows is 2 Billion.

What is the difference between DataGrid and DataGridView?

The DataGrid control is limited to displaying data from an external data source. The DataGridView control, however, can display unbound data stored in the control, data from a bound data source, or bound and unbound data together.

What is virtual mode in DataGridView?

With virtual mode, you can manage the interaction between the DataGridView control and a custom data cache. To implement virtual mode, set the VirtualMode property to true and handle one or more of the events described in this topic.


1 Answers

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.

like image 170
okarpov Avatar answered Sep 29 '22 21:09

okarpov