help please, i really need to solve this one.
when the quantity of the product is increasing/decreasing, i want the Total Price to update/increase/decrease also, but its only remain working.

the button is declare, so when i click the button , all of the info of that will be transfer/view in listview.

            Dim tbl As New Button
                tbl.Name = "" & rd.Item("nod").ToString()
                tbl.Text = tbl.Name
                tbl.Tag = "" & rd.Item("price").ToString()

''''this code is in other class''''

     Dim item as listviewItem
    item = lvorder.Items.Add("1") 'QTY
    item.SubItems.Add(btn.Name) 'Name of Dish
    item.SubItems.Add(btn.tag) 'Rate
    item.SubItems.Add((1 * Val(btn.tag)).ToString) 'Total Price

        For i As Integer = 0 To lvorder.Items.Count() - 1
    If lvorder.Items(i).SubItems(1).Text = btn.Text Then
    lvorder.Items(i).Text = (Val(lvorder.Items(i).Text) + 1).ToString
    lvorder.Items(i).Subitems(3).Text = (Val(lvorder.Items(i).Text) * Val(lvorder.Items(i).Subitems(2).Text)).ToString 'for Total Price
    ProdMatch = True
    Exit For
    End If
    Next

Recommended Answers

All 3 Replies

Put a breakpoint at

lvorder.Items(i).Text = (Val(lvorder.Items(i).Text) + 1).ToString

and see if the code stops there. If not then you are never getting a match. In that case put a breakpoint at

If lvorder.Items(i).SubItems(1).Text = btn.Text Then

and step through each iteration of the loop and check the values oof everything including btn.Text to see if things are what you expect. You might want to rewrite the loop as

For i As Integer = 0 To lvorder.Items.Count() - 1

    If  lvorder.Items(i).SubItems(1).Text = btn.Text Then

        dim quantity as integer = Val(lvorder.Items(i).Text + 1)
        dim unitcost as double = Val(lvorder.Items(i).SubItems(2).Text)
        dim total as double = quantity * unitcost

        lvorder.Items(i).Text = quantity.ToString
        lvorder.Items(i).SubItems(3).Text = total.ToString

        ProdMatch = True
        Exit For

    End If

Next

if only for debugging and you can add quantity, unitcost and total to the watch window.

Referrencing from your post
Do the same as you did in that post.

Private Sub clickMe(sendr As Object, ByVal e As EventArgs)
        Dim btn As Button = CType(sendr, Button)
        Dim ProdMatch As Boolean = False
        For i As Integer = 0 To lvorder.Items.Count() - 1
            If lvorder.Items(i).SubItems(1).Text = btn.Text Then
                lvorder.Items(i).Text = (Val(lvorder.Items(i).Text) + 1).ToString
                lvorder.Items(i).Subitems(3).Text = (Val(lvorder.Items(i).Text) * Val(lvorder.Items(i).Subitems(2).Text)).ToString 'for Total Price
                lblstotal.Text = Format(Val(lblstotal.Text) + Val(lvorder.Items(i).Subitems(3).Text), "0.00")   'Updating Total Value of all items
                ProdMatch = True
                Exit For
            End If
        Next

        If Not ProdMatch Then
            'Add the item at first time
            Dim item As ListViewItem
            item = lvorder.Items.Add("1") 'QTY
            item.SubItems.Add(btn.Name) 'Name of Dish
            item.SubItems.Add(btn.tag)  'Rate
            item.SubItems.Add(btn.tag)  'Total Price
            lblstotal.Text = Format(Val(btn.tag), "0.00") 'Updating Total Value of all items
        End If
        txtcash.Text = ""
    End Sub

It may help you.

Its working now, Thank you guys for helping :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.