Click to See Complete Forum and Search --> : DataTable columns


caffineplease
August 11th, 2003, 02:46 AM
Is there a way, which I'm sure there is, whereby I can create the number of columns of a DataTable at runtime? I have an ArrayList with the columns that I wish to have, but the size of the ArrayList is only known at runtime.

Btw, thanx to andy_tacker and bfarley for their help on the resizing issues. The Anchor technique worked a treat. Got some getting used to.

Best regards

John

Nightfall
June 30th, 2004, 06:08 AM
Try something like this (where list is your ArrayList):

DataTable dt = new DataTable();

for(int i = 0; i < list.Count; i++) {
dt.Columns.Add("" + i);
}


(""+ i) is an example for your column name. Here it is the index of the data in the arraylist.