How to bind a CollectionList to a Dataset ????

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

Does anyone know how to bind a System.Collection.ArraysList object to a
Dataset ?

Thanks for your reply

Regards
Serge
 
What do you mean by "Bind to a DataSet"?

If you mean binding like binding data to a control to show data, then you
can't. DataSet is not a control, it only exists in memory, you do not see
it.

If you mean to use data in the collection to make a DataSet, then yes (but
not binding, it has specific meaning). Simply declare and instantiate a
DataSet, add table to it and add rows to table, then use the data to
populate the rows.
 
HI,

That was exactly was I was doing, polulating the dataset with the content of
the arraylist collection. Actually after that work I bind the dataset to a
datagrid.

Actually the sequence I do is:
filling up my arrayList with some incoming data
Fill a datatable with rows of my arrayList data
Add the table to the dataset
Bind the dataset to a datagrid

I was thinking if tehre was a straight wayh to bind directly the arrayList
to the datagrid then ?

regards
serge
 
You cannot bind the ArrayList to the DataGrid but you can bind an IList.
Since ArrayList implements the IList interface you can cast the Arraylist
like so:
DataGrid.DataSource = (IList)ArrayList

Then all you have to do is set the DataGrid columns to any public properies
exposed by the items in your ArrayList and call the DataBind method of the
DataGrid.

It's just that easy...
 
Back
Top