lots of time binding large data table to datagrid

Nov 26 2009 10:52 AM

I have a large datatable (matrixdisplay) that includes 51 rows * 420 columns.
I want to bind only 50 columns. if I remove from datatable 370 columns even before binding , it is stuck for 3 minutes at least.
if I remove 200 columns and bind , it takes 10 sec which is great.
but if I remove another 150 columns it is stuck again.
this is my code : I copied the datatable twice.
//MatrixDisplay - contains 51*430
DataTable MatrixDisplayCopy = MatrixDisplay.Copy();

int amount_of_cols = 320;
for (int i = 0; i < amount_of_cols; i++)
{
MatrixDisplayCopy.Columns.RemoveAt(3);
}
//MatrixDisplayCopy contains 51*110 - binds to grid fast !!!
DataTable MatrixAnotherCopy = MatrixDisplayCopy.Copy();
for (int i = 0; i < 100; i++)
{
MatrixAnotherCopy.Columns.RemoveAt(3);
}

//MatrixAnotherCopy contains 51*10 - binds to grid SLOWWWWWWWW!!!
dgvMainMatrix.DataSource = MatrixAnotherCopy; //takes minuts!!
dgvMainMatrix.DataSource = MatrixDisplayCopy ; //takes 10 seconds!!
 
WHY ???

 

Answers (1)