some help with datagridview

dbnull

New member
Joined
Jun 23, 2016
Messages
2
Programming Experience
Beginner
hi, i am new to vb.net programming, my question is, i have 3 tables named as

Orders | OrderDetails | Products


Orders have PK_OrdersID and OrderDetails have FK_OrdersID of Orders so they are related with one to many relationship
Products have PK_ProductID and OrderDetails have FK_ProductID of Products they are also related with one to many relationship

OrderDetails is bound to datagridview and it shows columns as follow

DetailID - OrdersID - ProductID - Qutantity - Total

what i want is, i want to add 2 more column into OrderDetails Datagridview as ProductName and ProductPrice

and when i enter ProductID then ProductName and ProductPrice should fill up

i hope i make it understandable also my english is not good.
 
You could add the extra columns in code but I'd suggest doing so in the designer. You might want to add all the columns in the designer, to easily maintain the order. Simply set the DataPropertyName property of each column that you want to bind to the data source.

You'd then handle the CellValueChanged event of the grid, detect whether the cell whose value had changed was in the ProductID column and, if so, use the Value to get the corresponding name and price from the appropriate DataTable. You would then set the Values of the other two cells in the same row.

That said, would it perhaps be a better idea to not show the ProductID at all and rather have the user select a ProductName from a drop-down? That's easily done in a DataGridView.
 
Back
Top