Symptoms
In Visual Basic .NET or in Visual C# .NET, you can invoke the overloaded two-argument FindString method or the overloaded two-argument FindStringExact method of the ComboBox class or the ListBox class. However, when the startIndex parameter is equal to the index value of the last item of the associated list, you may receive the following error message:
An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in system.windows.forms.dll
Additional information: Specified argument was out of the range of valid values.If you handle this exception in a Try/Catch block, you may receive an error message similar to the following:
Unhandled Exception: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: startIndex
at System.Windows.Forms.ListBox.FindStringExact(String s, Int32 startIndex)
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in %Form Path%\Form Name:line 83Note Form Name is a placeholder for the file name of the Form that contains the ComboBox object or the ListBox object that invokes the FindString method or the FindStringExact method. Additionally, %Form Path% is a placeholder for the path of the previously mentioned Form.
Resolution
When you invoke either the two-argument FindString method or the two-argument FindStringExact method, a startIndex parameter is used. This startIndex parameter may be equal to the index value of the last item of the associated list for a ComboBox object or a ListBox object. In such cases, the invoked method is supposed to start searching from the beginning of the list for the string that is passed as the first parameter. However, the invoked method incorrectly begins the search after the last item of the list. Therefore, the list boundary is crossed during the search, and you receive the error message in the “Symptoms” section.