Partilhar via


CComboBox::SelectString

Searches for a string in the list box of a combo box, and if the string is found, selects the string in the list box and copies it to the edit control.

int SelectString(
   int nStartAfter,
   LPCTSTR lpszString 
);

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 –1, the entire list box is searched from the beginning.

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

Return Value

The zero-based index of the selected item if the string was found. If the search was unsuccessful, the return value is CB_ERR and the current selection is not changed.

Remarks

A string is selected only if its initial characters (from the starting point) match the characters in the prefix string.

Note that the SelectString and FindString member functions both find a string, but the SelectString member function also selects the string.

Example

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

// Select the item that begins with the specified string.
int nSel = m_pComboBox->SelectString(0, lpszSelect);
ASSERT(nSel != CB_ERR);

Requirements

Header: afxwin.h

See Also

Reference

CComboBox Class

Hierarchy Chart

CComboBox::FindString

CB_SELECTSTRING

Other Resources

CComboBox Members