1 year ago

#354066

test-img

phoebe

VB.NET DataGridview and Total

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

vb.net

datagridview

pos

0 Answers

Your Answer

Accepted video resources