Hi everyone!

I'm new to using VB and apparently I'm having a problem with the value being displayed in a textbox

Here's the thing:

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

        If DGV2.SelectedRows.Count = 0 Then
            Exit Sub
        End If

        Dim Sum As Decimal = 0
        For I = 0 To DGV2.Rows.Count - 1
            Sum -= DGV2.Rows(I).Cells(5).Value
            txtTotalPrice.Text = Sum.ToString("n2")
    End Sub

Everytime I add an item/row its Price which is the value of Cell(5) is being added to the variable name Sum and also the value is passed to txtTotalPrice which is the textBox. The problem is, whenever I delete a row, the price value of that row is deducted correctly but it returns a negative value.
can anyone tell me what may be the problem with my code, or is there a way to remove the negative sign.?

Any help will be very much appreciated. =) thanks in advance

There are 2 ways you can calculate the new total after removing an item from your "order".
1st you deduct the value you've removed from the total
2nd you add all the remaining values to get the new total.

I'm guessing you went for both ways at the same time.
Since you are declaring Sum for each record removed, it will be 0. Then from 0 you deduct all the prices currently found in your DGV2 (For I = 0 to DGV2.Rows.Count - 1 )
Change Sum -= DGV2.Rows(I).Cells(5).Value to Sum += DGV2.Rows(I).Cells(5).Value and you should be fine.

:) ah yes! you're right >.< thank you adam K.. ("-") can't beliwve this sign is the reason for my headache. geez..

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