0

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 :)

Pikoh
  • 7,582
  • 28
  • 53
Summer
  • 1
  • 1
  • Why are you using the `MouseMove`Event? – Pikoh Sep 04 '17 at 10:51
  • Use combobox selecteditem event – Ramankingdom Sep 04 '17 at 12:29
  • @pikoh i was looking for events that would display the subtotal as soon as I input a value in qty column... I tried some events though but some needs things to be clicked before it displays the subtotal. Any suggestions? – Summer Sep 04 '17 at 13:10
  • @ramankingdom thank you... however i cant find the selecteditem event on datagridview combobox... i guess its only available for combo boxes outside dgv – Summer Sep 06 '17 at 06:29
  • @ramankingdom I haven't heard about this since I'm new in vb But I'll take a look and study about interaction trigger. Thank you so much – Summer Sep 07 '17 at 12:09
  • sorry I am wrong I am thinking of wpf – Ramankingdom Sep 07 '17 at 12:44

0 Answers0