Populating a datagrid control ...

P

Prime

Hi All ...

I'm writing a small shopping cart app (uni assignment) and need to list all
the books that a user selects.

I have created a "BookBasket" object that contains among other things an
arraylist of the user selected books.
The "book" object contains isbn,title price and quantity information.

I'd like to display the contents of the BookBasket in a datagrid control.

I assume that to start with I'd have to iterate through the basket to
identify each books information, but then how do I populate the datagrid
manually?

It seems from what I've read,that it is easier to populate a datagrid from a
datasource, but I don't know how that would relate to what I'm doing.

any clues or links to examples would be much appreciated.

Thanks in advance

Prime.
 
K

Ken Cox [Microsoft MVP]

You can bind a datagrid to a simple array list. Is that what you meant?

Dim values As ArrayList = New ArrayList
values.Add("IN")
values.Add("KS")
values.Add("MD")
values.Add("MI")
values.Add("OR")
values.Add("TN")
DataGrid1.DataSource = values
DataGrid1.DataBind()
 
P

Prime

Hi Ken,

Thanks for the reply.

The array list contains "SelectedBook" objects which are instances of class
Book ... which are not simple data types.
eg:
public class Book
private strISBN as string
private strTitle as string
Private sngPrice as single
....

'Poperty procedures follow...
....
end class

Public class BookBasket
private arrSelectedBooks as arraylist = new arraylist
....
' property procedures etc follow ...

end class

I don't think a datagrid would be able to display the elements of the book
object without some special coding

Jared has pointed me to a good sample on gotdotnet which I am studying ... I
suspect it will do the job for me.

Thanks again for the reply.

Prime.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top