-
Totals go up by one!!
i've got the code below... my prob. is when i remove a quanitity or cost from their lstBoxs, the totals should be subtracted from that quantity or cost. but instead both totals go up by one???
no idea why :confused:
Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
If lstProduct.SelectedIndex <> -1 Then
quantity = CDbl(lstQuantity.SelectedIndex)
totalQuantity = Val(lblTotalQuantity.Text) - quantity
lblTotalQuantity.Text = CStr(totalQuantity)
totalQuantity = 0 ' Intialising totalQuantity
totalCost = CDec(Val(lblTotalCost.Text) - lstCost.SelectedIndex)
lblTotalCost.Text = CStr(totalCost)
totalCost = 0 ' initialising totalcost
lstQuantity.Items.RemoveAt(lstProduct.SelectedIndex)
lstCost.Items.RemoveAt(lstProduct.SelectedIndex)
lstProduct.Items.RemoveAt(lstProduct.SelectedIndex)
Else
MsgBox("PLease select an item to be removed")
End If
End Sub
-
probably becasue lstQuanity.SelectedItem and lstCost.selectedItem is returning -1
-
Use lstProduct.SelectedIndex to get the values.
-
i did that but,it's not deleteing any values
-
any ideas at all??