I have below piece of code which runs fine only except when the last index of Combobox is reached it gives the error as mentioned in Title. More details: Invalid Argument=Value of '17' is not valid for 'SelectedIndex'. Parameter name: SelectedIndex
The code runs through all the indices available in the Combo-box and gives the desired output. But when the last value is reached I get this error. Could someone please guide me?
Private Sub ExportButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportButton.Click
Dim LastItem As Integer = 0
LastItem = TagComboBox1.Items.Count
For i As Integer = 0 To LastItem
TagComboBox1.SelectedIndex = i
'CODE to perform some operation..
If TagComboBox1.SelectedIndex = LastItem Then
Exit For
End If
Next
End Sub