Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > What is the best way to write DGV handling very large data and having frequent updates?
 

What is the best way to write DGV handling very large data and having frequent updates?

Hello,

I need to design a DGV which will be having atleast 10, 000 rows of data. Further I will be getting frequent updates for each of these rows in the grid. In short the final code boils down to something like:

DataTable table = . ..;
dataGridView1.DataSource = table;

UpdateEventHandler(...)
{
if (KeySet.Contains(Update.Key())
{
// update the row in the DGV
}
else
{
// Well this is a new row.
table.Rows.Add(...)
}
}

Now, I understand that a Rows.Add(..) operation is going to cause the DGV repaint and hence bring down performance. But I don't know when an update comes and hence there is no way I can try the BeginUpdate/EndUpdate thing to avoid the repaint.

Please let me know what is the best way to tackle this and if possible how can I improve the performance of the above code (I am not using any fancy style feature here but still repainting takes a lot of time. Any suggestions to cut down the repaint time would be great!)


Thanks!
Asterix001  Wednesday, July 15, 2009 7:09 AM
Hi Asterix,

Since you'd like to load a large amount of data into the DataGridView on your form, why not implement virtual mode in the DataGridView for better performance?

Please read the following MSDN document on more information on virtual mode:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.virtualmode(VS.80).aspx

Hope this helps.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Monday, July 20, 2009 8:44 AM
You could try using a BindingSource and then adding records to the bindingsource. That may help with the repainting issues (though I did not try it).

Add a BindingSource to your form. Set the DataSource of the binding source to your table. Set the DataSource of your grid to your bindingSource. It basically sits between your table and your DataGridview and allows modifications.

Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Wednesday, July 15, 2009 3:52 PM
Hi Asterix,

Since you'd like to load a large amount of data into the DataGridView on your form, why not implement virtual mode in the DataGridView for better performance?

Please read the following MSDN document on more information on virtual mode:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.virtualmode(VS.80).aspx

Hope this helps.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Monday, July 20, 2009 8:44 AM

You can use google to search for other answers

Custom Search

More Threads

• DataSet, DataGridView and related tables
• DataGridView with Category/Subcategory combo boxes
• DataGridview ComboBox Handler Problem :(
• grid dispay
• Custom made Class in a Cell?
• Datagridview - making rows behave like columns
• DataGridView and CSV: first row not column headers
• Bind Data from a Access Database to a DataSet @ Runtime
• DataGrid / DataGridTextBoxColumn - getting around .NET bug?
• Problem with Commandbuilder