Question DataGridView Only Shows One Record!

mclark1129

New member
Joined
Apr 3, 2009
Messages
3
Programming Experience
1-3
Hello,

I have a class called 'Product' that I am trying to data bind to a DataGridView in a VB.net forms application. Product has a property named 'Details' which is a ProductModel object that contains the fields ID, ProductID, CategoryID, DistributorID, and Name. So I would normally access the information about a product by using myProduct.Details.Name or myProduct.Details.ProductID, etc. I have a shared method in Product called GetAllProducts that returns a List(Of Product) that contains, you guessed it, all the products in my database.

In my project I created a Business Object Datasource for my Product class and on the form in question, I've dragged a DataGridView from the toolbox onto the form. From the Datasources panel I expand my product class to reveal the 'Details' property, which I drag on to the DataGridView. Visual Studio creates a ProductBindingSource and the DataGridView shows all the fields from the Details property in an Access-like spreadsheet view in the designer.

In the code behind I select the form's Load event and enter the following code:

ProductBindingSource.Datasource = Product.GetAllProducts()

When I run the application and open the form, I am greeted with a DataGridView that shows only one row from my products table (which at the moment only has a total of 2 records). The only way for me to cycle to the next record is to use the BindingNavigator. If I do not have one then I am stuck. This obviously defeats the purpose of the DataGridView. I am also able to click the "*" row and enter a new record, but if I cycle to the next record in the list then the new record is lost. What do I need to:

1) Configure the DataGridView to display ALL the records returned in my List
2) Tell the DataGridView which methods to call on my business object in order to add or delete records?

TIA, this is really frustrating me especially as I feel I'm probably missing some mundane detail in the process.

Mike C.
 
Back
Top