System.Windows.Forms.ComboBox.FindString Method

Returns the index of the first item in the System.Windows.Forms.ComboBox that starts with the specified string.

Syntax

public int FindString (string s)

Parameters

s
The string to search for.

Returns

The zero-based index of the first item found; returns -1 if no match is found.

Remarks

The search performed by this method is not case-sensitive. The s parameter is a substring to compare against the text associated with the items in the combo box list. The search performs a partial match starting from the beginning of the text, and 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 System.Windows.Forms.ComboBox.ObjectCollection.Remove(object) 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 System.Windows.Forms.ComboBox, you must use the version of the ComboBox.FindString(string) method that provides a parameter for specifying a starting index within the System.Windows.Forms.ComboBox. If you want to perform a search for an exact word match instead of a partial match, use the ComboBox.FindStringExact(string) method.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0