Hello I creating a program and I need to add delete button but every time I ma trying to run the program an error comes (1)InvalidArgument=Value of '-1' is not valid for 'index'.Parameter name: index
here is my codes for the delete button
and here is also the codes for my list
here is my codes for the delete button
Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click If MsgBox("Are you sure you want to delete this item", _ MsgBoxStyle.OkCancel, "Confirm") = MsgBoxResult.Cancel Then Exit Sub End If lstDestination.Items.RemoveAt(destentionNo) For i = destentionNo To ndestentions - 1 sngTotals(i) = sngTotals(i + 1) strdestenations(i) = strdestenations(i + 1) sngmileages(i) = sngmileages(i + 1) sngRates(i) = sngRates(i + 1) Next i ndestentions = ndestentions - 1 txtDestination.Clear() txtTotal.Clear() txtMileage.Clear() txtRate.Clear() btndelete.Enabled = False btnamend.Enabled = False End Sub
and here is also the codes for my list
Dim index As Integer ' Determine which product the user selected index = lstDestination.SelectedIndex ' Get and display the product details [size="5"] txtDestination.Text = lstDestination.Items(index[/size])the error comes in here txtTotal.Text = Format(sngTotals(index), "#0.00") txtMileage.Text = sngmileages(index) txtRate.Text = sngRates(index) ' The product can be amended btnamend.Enabled = True End Sub