Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code so its public

Dim dt As New DataTable

in private sub form load

grd_order.DataSource = dt

in private sub for product list

Private Sub product_list(ByVal pid As String)
    Dim getproduct As String = "SELECT FLD_PRODUCT_ID,FLD_PRICE FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID='" & pid & "'"
    Dim reader As New OleDb.OleDbDataAdapter(getproduct, myconnection)
    Dim getcolumns As String = "SELECT FLD_QTY,FLD_SUBTOTAL FROM TBL_ORDERITEM_A154287 WHERE FLD_PRODUCT_ID='" & pid & "'"
    Dim reader2 As New OleDb.OleDbDataAdapter(getcolumns, myconnection)
End Sub


Now i want to know how to calculate the subtotal? because user can key in the quantity of the product they want. like in the picture : CK005 | 850 | , quantity and subtotal cells are empty. how would i get the value from cell Price and cell Quantity? to calculate the subtotal : Subtotal = valueFromQtyCell * valueFromPriceCell and put it into cell Subtotal for each its own row. Then get each value from column subtotal of each row and add them up as the Total Price; TotalPrice = valueFromSubtotalCellOfEachRow this im assuming needs a loop?

1 Year
Discussion Span
Last Post by nadiam

I found this article for you which should help explain it. Basically you need to use the SELECT statement to create the data for the other columns.

Edited by tinstaafl


You could also work with DGV.Rows(r).Cells(c).Value in some loops. Remember to cast the Value to the proper type.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.