Reputation: 521
I'm Filling a datagrid from a dataset, with information retrieved from a database. What i would like to do is take all the values from a particular column and put them into an array.
So for example a table named Ages, stored in a datagrid:
Ages
16
18
20
24
What i would like to is take the values out of the datagrid, without having to select them from the datagrid. Is this possible, can anyone send on a link or help on my problem, greatly appreciated.
Thanks
Upvotes: 1
Views: 1100
Reputation: 1230
Another solution is to grab all the values from the dataset that you used to populate the grid with:
DataSet ds = new DataSet();
List<object> myListArray = new List<object>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
myListArray.Add(dr["MyColumnName"]);
}
Upvotes: 2
Reputation: 3327
you could select the named property from all the items from the datagrids datasource into an enumeration with link and put the result into an array. Something like this:
(from DataRow row in datagrid.datasource as DataTable select row[columnName]).ToArray()
Upvotes: 0