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 DGV2.Rows.Remove(DGV2.SelectedRows(0)) Dim Sum As Decimal = 0 For I = 0 To DGV2.Rows.Count - 1 Sum -= DGV2.Rows(I).Cells(5).Value Next 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