Binding an Array List to a Data Grid Control

Weste

Newcomer
Joined
Feb 4, 2005
Messages
14
I am binding a data grid control to an array list that was populated via a data reader. The code is below


while (dataReader.Read())
{
Company company = new Company(dataReader.GetString(0), dataReader.GetString(1), dataReader.GetString(2));

companies.Add(company);
}

}
this.dgTest.DataSource = companies;

This first item in the data reader is the CompanyID, 2nd is CompanyName, and 3rd is ContactName.

When the data is displayed in the data grid the columns are reversed - ie the 1st column is ContactName, 2nd column is CompanyName, and 3rd is CompanyID.

How do I populate the data grid so the columns are in the same order as the data reader?

Thanks.
 
Back
Top