0
votes

I have a fairly large dataset (1000 rows), that I want to feed into a DataGridView in my Windows Forms application (.NET 3.5). Querying the data from a database, and building up the DataTable is very fast, but when I set the DataSource property of the DataGridView, it literally takes around a minute before the application becomes responsive.

I have tried setting DoubleBuffered to true using the wizardry of reflection, but this seems to have no effect. Any tips?

Just to clarify, the code that has the awful performance is simply this:

dgv1.DataSource = dt;

Where 'dt' is a DataTable I have built up

1
How many columns does the table have? Are you using any large (or binary) datatypes? You may also want to consider paging - and only binding the minimum rows necessary.christofr
1000 rows isn't extreme. Do you have any AutoColumnWidth settings?Henk Holterman

1 Answers

1
votes

I dont know how this would effect your application.

But depending on which event is initiating the population of the DataGridView, I would use a BackgroundWorker, which would work funny enough in the background, freeing up the application so it wouldnt look unresponsive. And also the background worker can report back to the main thread which called it, enabling you to implement some soft of update/progress bar.

As from own experience getting data from a datasource and binding it will always take some time to do.

protected BackgroundWorker _bw;
_bw = new BackgroundWorker;
_bw.DoWork += DoWorkMethod;

public void DoWorkMethod(object sender, DoWorkEventArgs e)
{
//Do work here.
}

Thats kind of the gist of it. You can use the Completed and UpdateProgress methods to help with displaying the progress bar etc...