Click here to Skip to main content
15,914,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
I have a piece of code, I can delete the first value but fails and give notice
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index

VB
Private Sub ComboBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
     If ComboBox1.Items.Count > 0 Then
         If e.KeyCode = Keys.Delete Then
             ComboBox1.Items.Remove(ComboBox1.SelectedItem)
             'or
             'ComboBox1.Items.RemoveAt(ComboBox1.SelectedIndex)
         End If
     End If
 End Sub


thank help !
Posted

After you delete the first item, selected index points to 0 which is not a valid index.
Set the selected item to a valid value and then delete again.
 
Share this answer
 
SQL
I declare If  ComboBox1.SelectedIndex > 0 Then
Can not delete the first value
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900