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
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 !

VulpesPosted Apr 1, 2014, 11:41 AM
VulpesPosted Apr 1, 2014, 11:06 AM
Shweta LodhaPosted Apr 1, 2014, 11:01 AM
fugio huynhPosted Apr 1, 2014, 10:54 AM
Shweta LodhaPosted Apr 1, 2014, 10:42 AM
When you will delete first item and then press the delete again, at that time your selected item will be null. Hence selectedIndex will be -1.
Unfortunately you will land up with an exception.