ComboBox.FindStringExact Method (String)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Finds the first item in the combo box that matches the specified string.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member FindStringExact : 
        s:string -> int

Parameters

s
Type: System.String

The String to search for.

Return Value

Type: System.Int32

The zero-based index of the first item found; returns -1 if no match is found, or 0 if the s parameter specifies Empty.

The search performed by this method is not case-sensitive. The s parameter is a string to compare against the text associated with the items in the combo box list. The search looks for a match starting from the beginning of the text, returning the first item in the list that matches the specified substring. You can then perform tasks, such as removing the item that contains the search text using the Remove method or changing the item's text. Once you have found the specified text, if you want to search for other instances of the text in the ComboBox, you must use the version of the FindStringExact method that provides a parameter for specifying a starting index within the ComboBox. If you want to perform partial word search instead of an exact word match, use the FindString method.

The following code example demonstrates how to initialize a ComboBox control by setting the MaxDropDownItems and DropDownStyle properties and using the FindStringExact methods to search the ComboBox. It also shows handling the SelectedIndexChanged event.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: