CB_SETCURSEL

3.0

CB_SETCURSEL
wParam = (WPARAM) index;  /* item index             */
lParam = 0L;              /* not used, must be zero */

An application sends a CB_SETCURSEL message to select a string in the list box of a combo box. If necessary, the list box scrolls the string into view (if the list box is visible). The text in the edit control of the combo box is changed to reflect the new selection. Any previous selection in the list box is removed.

Parameters

index

Value of wParam. Specifies the zero-based index of the string to select. If the index parameter is –1, any current selection in the list box is removed and the edit control is cleared.

Return Value

The return value is the index of the item selected if the message is successful. The return value is CB_ERR if the index parameter is greater than the number of items in the list or if index is set to –1 (which clears the selection).

Example

This example retrieves the number of items in the list box of a combo box and sends a CB_SETCURSEL message to select the last item in the list:

WORD cListItems;

cListItems = (WPARAM) SendDlgItemMessage(hdlg,
    ID_MYCOMBOBOX, CB_GETCOUNT, 0, 0);
SendDlgItemMessage(hdlg, ID_MYCOMBOBOX,
    CB_SETCURSEL,
    cListItems - 1,   /* zero-based index, so subtract one from total */
    0L);

See Also

CB_GETCURSEL, CB_FINDSTRING