Hi guys,
I have a listview that displays "product Description" in the first column and "Product Price" in another column, after the "add" button is clicked on frmSales form. After that, txtAmountDue is automatically updated with the value of the items added to the listview.

The Remove Button, when clicked, removes the selected item from the listview.

What I want is the code to deduct the value of the item removed from the listview from the Amount in txtAmountDue, when the remove button is clicked.
I have tried to the code below

Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click


        For ICount = lsv1.Items.Count - 1 To 0 Step -1
            If lsv1.Items(ICount).Selected Then
                lsv1.Items(ICount).Remove()

                Dim pSum As Double
                For Each item As ListViewItem In lsv1.Items
                    pSum -= CInt(item.SubItems(1).Text)

                    txtAMDue.Text = pSum.ToString("N2")
                Next
            End If
            Application.DoEvents()

        Next



    End Sub

But instead, is seemingly is deducting the total from the value of the selected item, giving me a negative figure.

May someone help me please.

Try this. You will have to change the naming. I have a Label which is Label2 which acts as a Total price or (Current Total) and I'm using ListView4.

 For Each iItem As ListViewItem In ListView4.SelectedItems
 ' I declared the variables I will use to keep track here.
 Dim Price_To_Deduct As Integer ' I used Integer because I didn't format the numbers to money format so you can try using Double but I haven't tested that.
 Dim Current_Total_Price As Integer ' This variable will contain the current total price which we will deduct from.
 Dim New_Total As Integer ' This will contain the new total.

 Price_To_Deduct = iItem.SubItems(1).Text
 Current_Total_Price = Label2.Text ' Retrieving the current total price so that we will do calculations.
 New_Total = Current_Total_Price - Price_To_Deduct
 ' Because I'm using a Label I now have to clear it and reUpdate it with the new total.
 Label2.Text = ""
 Label2.Text = New_Total
 Next

This should work.

More shortly the codes should be

For Each iItem As ListViewItem In ListView4.SelectedItems

    Label2.Text = Val(Label2.Text) - Val(iItem.SubItems(1).Text)

    'And also remove the selected Item here
Next

Hope it can help you.

That's great. I think you may now mark this question as solved then.

This question has already been answered. Start a new discussion instead.