VB.NET DataGridview 和 Total
我正在尝试使用vb.net建立POS系统。我使用DataGridView显示项目,数量和数量。每当您单击项目所在的按钮时,它都会在DataGridView中进行更新。第三列是金额。总金额将显示为“总”。但是,每当我多次单击一个项目时,例如,每项50的金额,数量为3,因此总计150,但仅显示总金额为50。
我期望发生的是数量乘以数量和金额的总数(2x50 = 100),但发生的是(2x50 = 50),
这是我使用的代码: --------对于总计
Private Function Total_of_Products() As Double
Dim Sum As Double = 0
Dim i As Integer = 0
For i = 0 To DataGridView1.Rows.Count - 1
Sum = Sum + Convert.ToDouble(DataGridView1.Rows(i).Cells(2).Value)
Next i
Return Sum
End Function
Sub TotalProducts()
If DataGridView1.Rows.Count > 0 Then
total.Text = (Total_of_Products().ToString("0.00"))
End If
End Sub
------------------------------------------------------
Private Sub toolbox_Click(sender As Object, e As EventArgs) Handles toolbox.Click
Dim CostofItem As Double = 20
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells(0).Value = "toolbox" Then
row.Cells(1).Value = Double.Parse(row.Cells(1).Value) + 1
row.Cells(2).Value = CostofItem * Double.Parse(row.Cells(1).Value)
Exit Sub
End If
Next
DataGridView1.Rows.Add("toolbox", "1", CostofItem)
TotalProducts()
End Sub
I am trying to make a POS system using VB.net. I used datagridview to show the item, quantity, and amount. Everytime you click the button where the item is located, it will update in the datagridview. The third column is the amount. the total amount will show in "TOTAL". But whenever i click an item more than once, example, the amount is 50 per item and the quantity is 3, therefore it should show in TOTAL 150, but it only shows the total amount is 50.
What i expect to happen is that the multiplied amount in qty and amount will show up in TOTAL section (2x50 = 100) but what happened is (2x50 = 50)
This are the codes I used:
---------For Total-----------
Private Function Total_of_Products() As Double
Dim Sum As Double = 0
Dim i As Integer = 0
For i = 0 To DataGridView1.Rows.Count - 1
Sum = Sum + Convert.ToDouble(DataGridView1.Rows(i).Cells(2).Value)
Next i
Return Sum
End Function
Sub TotalProducts()
If DataGridView1.Rows.Count > 0 Then
total.Text = (Total_of_Products().ToString("0.00"))
End If
End Sub
----------For the Item------------
Private Sub toolbox_Click(sender As Object, e As EventArgs) Handles toolbox.Click
Dim CostofItem As Double = 20
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells(0).Value = "toolbox" Then
row.Cells(1).Value = Double.Parse(row.Cells(1).Value) + 1
row.Cells(2).Value = CostofItem * Double.Parse(row.Cells(1).Value)
Exit Sub
End If
Next
DataGridView1.Rows.Add("toolbox", "1", CostofItem)
TotalProducts()
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论