Skip to main content

BaseListBoxControl.FindString(String) Method

Finds the first item in the list box control starting with the specified string.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public int FindString(
    string s
)

Parameters

Name Type Description
s String

A string value representing the search text.

Returns

Type Description
Int32

An integer value representing the zero-based index of the first item found. -1 if no item is found.

Remarks

This method searches for the first item that starts with the specified string. You can then remove the item containing the search text by using either the Remove or RemoveAt methods. You can also change the item’s text. Note: the search is not case-sensitive. If you need to search for further instances of the text in the list box control, you can use a FindString method override and provide a parameter to specify a start index.

If you want to search for an exact word match instead of a partial match, use the BaseListBoxControl.FindStringExact method.

Example

The following sample code declares a DeleteItems method. This method provides search of items whose display text starts with the string specified by the s parameter (“Chicago”) within the ListBoxControl item’s collection. If found, the method removes them from the items collection.

Note: this method works if no data source is bound to the list box control. Otherwise, method execution will not take place.

The image below demonstrates the ListBoxControl control’s look & feel before and after sample code execution.

BaseListBoxControl - FindString

using DevExpress.XtraEditors;
// ...
private void DeleteItems(ListBoxControl listBox, string s) {
    int index = listBox.FindString(s);
    if (index == -1) return;
    while (index != -1) {
        listBox.Items.RemoveAt(index);
        index = listBox.FindString(s, index);
    }
}
// ...
DeleteItems(listBoxControl1, "Chicago");

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FindString(String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also