アイテムがすでにDataGridView
に存在する場合に問題があり、同じアイテムを再度入力すると、数量と合計が増減しません。同じ項目が表示されます。DataGridViewの既存のアイテムに数量を追加する方法
Item Code ProductName Unit Item Description Price Quantity Total Discount
06-098 Biogesic 500mg Paracetamol 5.50 1 5.50 0.00
これは、入力にTextBox
バーコードを持っており、それがDataGridView
の項目が一覧表示されます。ここで
は私のコードです:
Private Sub txtbxBarcode_TextChanged(sender As Object, e As EventArgs) Handles txtbxBarcode.TextChanged
GetProductInfo()
End Sub
Private Sub GetProductInfo()
Dim discountAmount As Double
Dim medicineName, unit As String
Try
SQL = "SELECT product_code, Medicine_name, Unit, Description, Price, medicineID FROM medicine_info WHERE barcode = '" & txtbxBarcode.Text & "'"
ConnDB()
cmd = New MySqlCommand(SQL, conn)
dr = cmd.ExecuteReader
If dr.Read = True Then
txtbxItemCode.Text = dr("product_code")
unit = dr("Unit")
medicineName = dr("Medicine_name")
txtbxItemDesc.Text = dr("Description")
'Validate Discount
If isDiscount = True Then
discountAmount = Val(dr("Price")) * (Val(discountPercent)/100)
txtbxPrice.Text = Format(Val(dr("Price")) - discountAmount, "#,##0.00")
Else
txtbxPrice.Text = Format(dr("Price"), "#,##0.00")
discountAmount = 0
End If
'Validate Quantity
If isQuantity = True Then
txtbxQuantity.Text = noOfItems
Else
txtbxQuantity.Text = 1
End If
txtbxTotal.Text = Format(Val(txtbxPrice.Text.Replace(",", "")) * Val(txtbxQuantity.Text), "#,##0.00")
'Adding Item to Gridview to Display
dgv.Rows.Add(dr("medicineID"), dr("product_code"), dr("Medicine_name"), dr("Unit"), dr("Description"), txtbxPrice.Text, txtbxQuantity.Text, txtbxTotal.Text, Format(discountAmount * Val(txtbxQuantity.Text), "#,##0.00"))
'Get Basket Info
BasketInformation()
'Clear Barcode text field
txtbxBarcode.Clear()
'Set Discount to Zero
discountPercent = 0
isDiscount = False
'Set Quantity to False
isQuantity = False
noOfItems = 1
End If
Catch ex As Exception
MsgBox(ex.ToString)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub
ようこそスタックオーバーフロー。あなたはあなたの質問を改善することができます。 [最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)をお読みください。あなたのコードが何も特別な問題であなたの正確な問題を示すとき、あなたはボランティアしてあなたを助ける人たちに敬意を表しています。 – zhon
あなたのお手伝いをさせていただきます。 – zhon
datagridviewの値そのものではなく、datagridviewの基になるデータソースを追加/更新する必要があります –