Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid is freezing when I add 1000 rows

Status
Not open for further replies.

dotnetguy

Programmer
Apr 13, 2005
7
US
I have an array of about 1000 items that I want to display in a datagrid.
Currently, I created a array object for each item, copy the data to the data
row, then add the row to the datatable

foreach (items o in c)
{

object[] data = new object[]{c.Name,

pdp,

countryName,

c.PhoneNumber,

c.UserDefined,

Int32.Parse(c.ContactId),

imageList1.Images[1]};

this.contactDataSet.Tables["Contacts"].LoadDataRow(data,true);


}

This is taking about 15 seconds to complete 1000 rows. Can anyone suggest a
technique to make this process faster. Can all the rows be added in bulk,
instead of one at a time? Could there be some constraint checking that slows
down the above process?





Thanks

Mogli.
 
before you add the rows, add this line:

contactDataSet.BeginUpdate();

and when all done, add this line:

contactDataSet.EndUpdate();

should notice a nice boost in performance.
 
My mistake, there is not Begin/End update methods for DataGrid, I was thinking windows controls, not web.

Not sure how to help with this one.

 
thanks for response,
I am using windows datagrid.

Thanks
M
 
You probably want to enable some sort of paging mechanism in your datagrid. You're loading 1000 rows into a control where you may only view 30 records at a time.

Maybe I'm not getting it, but why are you using an array here instead of creating datarows to add to the datatable?

The link below describes how to do it with a dataset.


The wisest people are those who are smart enough to realize they don't know it all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top