Condividi tramite


CListBox::FindString

Finds the first string in a list box that contains the specified prefix without changing the list-box selection.

int FindString(
   int nStartAfter,
   LPCTSTR lpszItem 
) const;

Parameters

  • nStartAfter
    Contains the zero-based index of the item before the first item to be searched. When the search reaches the bottom of the list box, it continues from the top of the list box back to the item specified by nStartAfter. If nStartAfter is –1, the entire list box is searched from the beginning.

  • lpszItem
    Points to the null-terminated string that contains the prefix to search for. The search is case independent, so this string may contain any combination of uppercase and lowercase letters.

Return Value

The zero-based index of the matching item, or LB_ERR if the search was unsuccessful.

Remarks

Use the SelectString member function to both find and select a string.

Example

   // The string to match.
LPCTSTR lpszmyString = _T("item");

// Delete all items that begin with the specified string.
int nIndex = 0;
while ((nIndex = m_myListBox.FindString(nIndex, lpszmyString)) != LB_ERR)
{
   m_myListBox.DeleteString( nIndex );
}

Requirements

Header: afxwin.h

See Also

Reference

CListBox Class

Hierarchy Chart

CListBox::SelectString

CListBox::AddString

CListBox::InsertString

LB_FINDSTRING

Other Resources

CListBox Members