System.Windows.Forms.ListBox.FindString Method

Finds the first item in the System.Windows.Forms.ListBox that starts with the specified string. The search starts at a specific starting index.

Syntax

public int FindString (string s, int startIndex)

Parameters

s
The text to search for.
startIndex
The zero-based index of the item before the first item to be searched. Set to negative one (-1) to search from the beginning of the control.

Returns

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

Remarks

The search performed by this method is not case-sensitive. The search looks for words that partially match the specified search string parameter, s. You can use this method to search for the first item that matches the specified string at the specified starting index within the list of items for the System.Windows.Forms.ListBox. You can then perform tasks such as removing the item that contains the search text by using the System.Windows.Forms.ListBox.ObjectCollection.Remove(object) method or changing the item's text. This method is typically used after a call has been made using the version of this method that does not specify a starting index. Once an initial item has been found in the list, this method is typically used to find further instances of the search text by specifying the index position in the startIndex parameter of the item after the first found instance of the search text. If you want to perform a search for an exact word match instead of a partial match, use the ListBox.FindStringExact(string) method.

Note:

When the search reaches the bottom of the System.Windows.Forms.ListBox, it continues searching from the top of the System.Windows.Forms.ListBox back to the item specified by the startIndex parameter.

Requirements

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