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.NET
Private Sub ComboBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDownCode
If ComboBox1.Items.Count > 0 ThenCode
If e.KeyCode = Keys.Delete ThenCode
ComboBox1.Items.Remove(ComboBox1.SelectedItem)Code
'orCode
'ComboBox1.Items.RemoveAt(ComboBox1.SelectedIndex)Code
End IfCode
End IfCode
End Subthank help !


Shweta LodhaRank #31 · 39.8K reputationPosted Apr 1, 2014, 6:42 AM EDT
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.
fugio huynh41 reputationPosted Apr 1, 2014, 6:54 AM EDT
Shweta LodhaRank #31 · 39.8K reputationPosted Apr 1, 2014, 7:01 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 1, 2014, 7:06 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 1, 2014, 7:41 AM EDT