CB_SELECTSTRING

3.0

CB_SELECTSTRING
wParam = (WPARAM) indexStart;          /* item before first selection */
lParam = (LPARAM) (LPCSTR) lpszSelect; /* address of prefix string    */

An application sends a CB_SELECTSTRING message to search for a string in the list box of a combo box and, if the string is found, to select the string in the list box and copy it to the edit control.

Parameters

indexStart

Value of wParam. Specifies 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 the indexStart parameter. If indexStart is –1, the entire list box is searched from the beginning.

lpszSelect

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

Return Value

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

Comments

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

If the combo box's style is owner-drawn but not CBS_HASSTRINGS and CBS_SORT, CB_FINDSTRING is used. If the styles are owner-drawn and CBS_SORT but not CBS_HASSTRINGS, WM_COMPAREITEM messages are sent.

Example

This example searches the entire list box of a combo box for the string “my string” and, if the string is found, selects it:

DWORD dwIndexFoundString;

dwIndexFoundString = SendDlgItemMessage(hdlg, ID_MYCOMBOBOX,
    CB_SELECTSTRING, -1, (LPARAM) ((LPCSTR) "my string"));

See Also

CB_FINDSTRING