ListBox.FindStringExact Method (String)
Finds the first item in the ListBox that exactly matches the specified string.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The search performed by this method is not case-sensitive. The search looks for an exact match to the words specified in the search string parameter, s. You can use this method to search for the first item that matches the specified string. You can then perform tasks such as removing the item that contains the search text by 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 ListBox, you can use the version of the FindStringExact method that provides a parameter for specifying a starting index within the ListBox. 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 use the ListBox.FindStringExact method to search a ListBox control for an item that exactly matches a specified string. If no items are found that match the search string, FindStringExact returns a -1 value and the example displays a MessageBox. If an item is found that matches the search text, the example uses the SetSelected method to select the item in the ListBox.