How can I update datagrid while table is being filled??

V

VM

Initially, I had created my Windows application so that my datagrid's source
would be updated once the method that filled the table was finished:

private void btn_run_Click(object sender, System.EventArgs e)
{
...
myTable = Match.fillTable();
datagrid.datasource = myTable;
}
public DataTable fillTable ()
{
...
for (int i=0; i<10000;i++)
{
//Creates row and adds it to my datatable myTable
}
return myTable;
}

The user wouldn't see anything in the grid for about 2-3 seconds but that
was an acceptable amount of time. But now, instead of a 10,000 row loop,
it'll be a loop of 400,000+ rows (about 1.5 minutes that user will be
staring at blank grid) . We already know that it displays the 400,000 rows
in the grid but I'd like to be able to update the grid every 10,000 rows so
the user can scroll through the grid while the table's filling up in the
background.

How would I have to modify the code?

Any help is appreciated.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

VM,

I don't think that you can do this, and it does raise the question of
what you are trying to do that requires 400K+ rows of information to be
shown at one time?

What I would do in this situation is create the table that has no rows
in it and then bind to that. Once you do that, you should then fill the
table in another thread. That thread would then call Invoke on the data
grid, passing a delegate that will call a function that makes the call to
add the row to the table. This way, you can get a little more interaction
when displaying rows of the grid. However, it might take longer overall,
because you are going to be making these calls across threads to do so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top