我有一个包含5列的数据网格视图(4个dgvtextbox和一个dgv组合框) dgv combobox(unit)与我的访问dbase绑定。
我的dgv看起来像这样:
INGREDIENTS | QUANTITY | UNIT | PRICE | SUBTOTAL
我想根据我的dgvcombobox选择和成分列中的项目自动显示我的价格(保存在dbase上)。例如:我的配料栏上的项目是“糖”,我在单位栏(dgv组合框)上选择了“tsp”,然后在dbase上保存的tsp糖价会自动显示在价格栏上。
(访问查询是从ingredientsTABLE中选择价格,其中单位和成分= dgv值)
我的代码是这样的:
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
希望你能帮助我...非常感谢:)。