Mark Mark - 13 days ago 5
C# Question

Slow to set DataGridView DataSource to DataTable in C#

I have a DataTable, fully populated, which I want to set to a DatagridView:

gdv.DataSource = dt;


However, this is painfully slow. The filling of the DataTable is very quick, but just this one line above takes ages. Is there any way to speed this up or perform it in another thread?

There is no interaction after this point. Just the simple statement above!

Thanks.

Answer

Check the formatting options, especially the Fill -related properties. Adjusting columnwidths for all rows involves a lot of calculation.