I have a datagridview with 5 columns (4 dgvtextbox and a dgv combobox) dgv combobox (unit) is binded with my access dbase.
my dgv looks like this:
INGREDIENTS | QUANTITY | UNIT | PRICE | SUBTOTAL
I would like my price(saved on dbase) to be displayed automatically based on my dgvcombobox selection AND items on ingredients column . For example: The item on my ingredients column is "sugar" and I selected "tsp" on unit column(dgv combobox) then price for tsp sugar which is saved on dbase will automatically be displayed on price column.
(the access query is to select price from ingredientsTABLE where unit and ingredient = dgv value)
my code goes like this:
Private Sub DataGridView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgvINGREDIENTS.MouseMove
''ADDING ITEMS FROM 2 COLUMNS IN DATAGRIDVIEW
For Each row As DataGridViewRow In dgvINGREDIENTS.Rows
Dim txtunit = row.Cells("col_unit").Value
Dim txtingredients = row.Cells("col_ingredients").Value
Dim unitquery As String = "SELECT price from INGREDIENTS where unit = '" & txtunit & "' AND ingredient='" & txtingredients & "' "
row.Cells("col_price").Value = unitquery
'row.Cells("col_sub").Value = row.Cells("col_qty").Value * row.Cells("col_price").Value
row.Cells("col_sub").Value = row.Cells("col_qty").Value * row.Cells(unitquery).Value
Next
'' GET COLUMN TOTAL VALUE IN DATAGRIDVIEW AND DISPLAY TO LABEL
Dim total As String = 0
For i As Integer = 0 To dgvINGREDIENTS.RowCount - 1
total += dgvINGREDIENTS.Rows(i).Cells(4).Value
Next
label_total.Text = total
End Sub
hope you could help me... Thanks much :)