Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have populated a DataTable . . . it has approximately 350 rows with 60 columns.

When I call . . .

DataGridView1.DataSource = csvData; //This is where rows in datatable are copied to dgv . . . for 350 clients time to populate is 20-25 sec.

Is 20-25 sec a reasonable time for execution of above? I have set DataGridView1 virtual set to true. I am thinking the time is excessive . . any tricks to increase speed?

Finally, if the execution time is reasonable, how would you implement a progress bar run in sync with the call to bind data to the grid? Where would you get the value to provide to the bar?
Posted
Updated 2-Feb-14 4:37am
v3

1 solution

If the line of code you're executing is setting the DataSource and that line takes 20+ seconds to run, no there is nothing you can do to speed that line up. You just have too much information you're binding to all at once.

You can try setting the DGV VirtualMode property to true. You'll have to provide a bit more code to handle the events that are now going to fire from the grid. You can find a tutorials on it here[^].

Basically, you're providing code to be the DataSource instead of providing just the data. This allows you to provide data for only the rows that the grid will display, speeding things up quit a bit.
 
Share this answer
 
Comments
JOHNNYDEMICHAEL 2-Feb-14 10:12am    
Dave . . . Thanks . . I've reviewed the code to handle the various events. The example seems to deal with populating the grid directly and not using DataTable to bind. Populating my DataTable is very quick . . its the binding to DGV that takes the time. Should I not be using a DataTable . . . & load data directly to the DataGridView? I thought I was speeding things up by using a DataTable.
Dave Kreskowiak 2-Feb-14 14:34pm    
load data directly to the DataGridView

You want it to go slower?? That's what is going to happen if you do that.

The point behind VirtualMode is that you only return the records that are VISIBLE to the user, not the entire set of records. As the grid is scrolled around, it'll call you for more records as needed. This is what speeds things up. The grid doesn't waste a ton of time preparing grid rows for all 350 records if it's only going to show 20 of them.
JOHNNYDEMICHAEL 12-Feb-14 7:09am    
Dave . . . your comments were very helpful . . . I now understand much about how VirtualMode works. Your comments have enabled me to resolve my problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900