I generally add my rows like so: for (int i=0;i<userList.Count;i++) { tblUsers.Rows.Add(new object[] {user.lastName, user.FirstName}); } Also, using a for loop instead of a foreach helps a little. Additionally, why not have .getUsers() return a UserDirectoryObject[]? You can bind an array to a DataGrid. Just some suggestions. Jay
-----Original Message----- From: Scott A. Lawrence [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 06, 2004 2:08 PM To: [EMAIL PROTECTED] Subject: [ADVANCED-DOTNET] Fastest way to add contents of ArrayList to a DataTable I'm writing a user profile tool that manipulates information in an LDAP server. I'm using an abstraction layer that talks directly to the server (written by another developer). The function of the abstraction layer that returns a list of all the users in LDAP returns an ArrayList. For easier filtering and sorting of this data, I build a DataTable in code, returning its default view so it can be bound to a DataGrid. The app currently takes between 15-20 seconds to load approximately 800 users from the LDAP source into memory, cache the user information, and display the page (DataGrid displays 20 users per page). The vast majority of that time (13-18 seconds) is consumed by the foreach loop that puts each ArrayList element into the The code in question looks like the following: ArrayList userList = theDirectory.getUsers(); if (userList != null) { foreach (UserDirectoryObject user in userList) { DataRow drUser = tblUsers.NewRow(); drUser["lastName"] = user.lastName; drUser["firstName"] = user.firstName; /* etc */ tblUsers.Rows.Add(drUser); } } tblUsers.DefaultView.Sort = "lastName"; return tblUsers.DefaultView Any suggestions about how to increase the speed of this would be greatly appreciated. Thanks! =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com ------------------------------------------------------------ The information contained in this message is confidential proprietary property of Nelnet, Inc. and its affiliated companies (Nelnet) and is intended for the recipient only. Any reproduction, forwarding, or copying without the express permission of Nelnet is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to this e-mail. ------------------------------------------------------------ =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com