Skip to main content
A newer version of this page is available. .

BaseListBoxControl.FindStringExact(String, Int32) Method

Finds the first item which matches the specified string exactly.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v19.2.dll

Declaration

public int FindStringExact(
    string s,
    int startIndex
)

Parameters

Name Type Description
s String

A string value specifying the search text.

startIndex Int32

An integer value representing the zero-based index of the first item to be searched.

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 exactly matches the search text. The startIndex parameter specifies where the search starts. Set it to -1 to search from the beginning of the list box control. Note, the search is not case-sensitive.

If you want to search for 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