Skip to main content

BaseListBoxControl.FindStringExact(String) Method

Finds the first item in the list box control which matches the specified string exactly.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public int FindStringExact(
    string s
)

Parameters

Name Type Description
s String

A string value specifying 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 with text that matches the search text exactly. Note: the search is not case-sensitive.

If you want to search for a partial text, use the BaseListBoxControl.FindString method.

Example

The following sample code declares a DeleteSameItems method. This method searches for the item specified by the s parameter. If found, it searches for items same as that specified and removes them from the list box items collection. As a result, only one item specified by the parameter is displayed.

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

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

BaseListBox - FindStringExact

private void DeleteSameItems(ListBoxControl listBox, string s){
   // the index of the first found item within the ListBoxControl
   int index = listBox.FindStringExact(s);
   if (index == -1 || index == listBox.ItemCount - 1) return;
   index++;
   while (index <= listBox.ItemCount - 1){
      if (listBox.FindStringExact(s, index) != -1){
         index = listBox.FindStringExact(s, index);
         listBox.Items.RemoveAt(index);
      }
      else
         break;
   }
}
// ...
DeleteSameItems(listBoxControl1, "Chicago");
See Also