Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CartItemCollection to Datagrid..?

Status
Not open for further replies.

matthewking

Programmer
Jul 15, 2002
75
ES
Hi all,

Say I had a CartItem class which represented a single cart item, and a CartItemCollection class which contains (not sure if this is how its done) a arraylist of CartItem objects..

How do I bind this data to a datagrid? create a datagrid in the CartItemCollection and return it? or is there a easier/standard way

MyDataGrid.DataSource = MyItemCollection.ToDataGrid(); for example ?

Thanks,
Matt.
 
Palbano, Thanks for your reply. I know how to do it technically, but the CartItemCollection itself just contains instances of CartItem class, and I don't believe datagrid will automatically read the public variables of CartItem and print to the datagrid.

So if I had a method called "ToDataSet()" in the CartItemCollection which would loop through CartItems and populate a dataset, then return that I could use that to populate a datagrid.

I was just wondering if this is technically ok, IE not a bad idea, or if theres a far simpler method of getting the same result.
 
morefire -
Why not give it a try?

I haven't done it myself, but I suspect that all you'll have to do is override the ToString method in your CartItem class to properly format the data. (since ToString is exposed by the Object class, and every class inherits from Object, every class thus has a ToString method whether you provide your own implementation or not)

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
>> I guess it wouldn't hurt to give it a go

[red]Better be careful![/red] With an attitude like that you will become an experienced programmer! Then you will have to answer questions on some online forum < barf >

Oh... never mind...

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top