HeaderPane
Main
Hide
Share Link
Print

SelectString

Searches a string and selects the matching item.

C

LONG WINAPI SftBox_SelectString(HWND hwndCtl, LONG start, int col, LPCTSTR lpszString, BOOL fWrap);
LONG WINAPI SftBox_SelectStringCase(HWND hwndCtl, LONG start, int col, LPCTSTR lpszString, BOOL fWrap);

C++

LONG CSftBox::SelectString(LONG start, int col, LPCTSTR lpszString, BOOL fWrap);
LONG CSftBox::SelectStringCase(LONG start, int col, LPCTSTR lpszString, BOOL fWrap);

Parameters

hwndCtl

The window handle of the combo box control.

start

The zero-based index of the item preceding the first item to be searched. The search starts with the item following start. Specify -1 to search all items, starting with the first item.

col

The zero-based column number to be searched. Specify -1 to search all columns.

lpszString

The string to be searched.

fWrap

Set to TRUE to continue the search with the first item once the last item has been reached. The search then ends with the item start. Set to FALSE to end the search with the last item, so no item is searched if start is the last item. This parameter is ignored if start is -1.

Returns

The return value is the zero-based index of the item where the string was found. -1 is returned if the string was not found or an error occurred.

Comments

The SelectString and SelectStringCase functions search a string and select the matching item.

The string lpszString is compared to the cell text (see GetText) of each item, starting with the item following start. The search is restricted to the column specified by col (all columns are searched if col is -1). If an item with matching text is found, it becomes the selected item (see SetCurSel), it is made visible in the dropdown portion (see MakeRowVisible) and its zero-based index is returned. If no matching item is found, the combo box no longer has a selected item and -1 is returned.

If the cell text starts with the string in lpszString, it is considered a match. When using SelectString, the comparison of lpszString and the cell text is not case sensitive. SelectStringCase performs a case sensitive comparison. The strings are compared using the locale defined using SetLocale. To select an item with exactly matching text use SelectStringExact or SelectStringExactCase.

If the fSelectEnabledItemsOnly member of the SFTBOX_CONTROL structure is set to TRUE (see SetControlInfo), disabled items are not searched.

FindString can be used to search for an item without selecting it.

The following table shows examples using SelectString:

lpszStringCell TextMatchComment
ABCabcYesSame string, case is ignored (no match when using SelectStringCase)
abcabc123YesStarts with lpszString
abcThisabcNoDoesn't start with lpszString
abcabNoDoesn't contain the complete lpszString

In a combo box control using a virtual data source, these functions cannot be used. -1 is returned and the combo box no longer has a selected item.

See Also C/C++ API | Categories | Notifications


Last Updated 11/21/2026 - (email)
© 2026 Softel vdm, Inc.