HeaderPane
Main
Hide
Share Link
Print

SelectStringExact

Searches a string and selects the exactly matching item.

C

LONG WINAPI SftBox_SelectStringExact(HWND hwndCtl, LONG start, int col, LPCTSTR lpszString, BOOL fWrap);
LONG WINAPI SftBox_SelectStringExactCase(HWND hwndCtl, LONG start, int col, LPCTSTR lpszString, BOOL fWrap);

C++

LONG CSftBox::SelectStringExact(LONG start, int col, LPCTSTR lpszString, BOOL fWrap);
LONG CSftBox::SelectStringExactCase(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 SelectStringExact and SelectStringExactCase functions search a string and select the exactly 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 if col is -1). If an item with exactly 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 is identical to the string in lpszString, it is considered a match. When using SelectStringExact, the comparison of lpszString and the cell text is not case sensitive. SelectStringExactCase performs a case sensitive comparison. The strings are compared using the locale defined using SetLocale. To select an item whose text starts with lpszString use SelectString or SelectStringCase.

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

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

The following table shows examples using SelectStringExact:

lpszStringCell TextMatchComment
ABCabcYesSame string, case is ignored (no match when using SelectStringExactCase)
abcabc123NoNot the same string
abcThisabcNoNot the same string
abcabNoNot the same string

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

Examples

C View entire sample code

INT_PTR CALLBACK MainDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_INITDIALOG:
        SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_APP)));
        InitStates(GetDlgItem(hwndDlg, IDC_STATE), COL_NAME);
        InitStates(GetDlgItem(hwndDlg, IDC_ABBR), COL_ABBR);
        InitCities(GetDlgItem(hwndDlg, IDC_CITY));
        SftBox_SelectStringExact(GetDlgItem(hwndDlg, IDC_STATE), -1, COL_NAME, TEXT("Florida"), FALSE);
        SftBox_SelectStringExact(GetDlgItem(hwndDlg, IDC_ABBR), -1, COL_ABBR, TEXT("FL"), FALSE);
        SftBox_SetCurSel(GetDlgItem(hwndDlg, IDC_CITY), 0);
        ShowStatus(hwndDlg, GetDlgItem(hwndDlg, IDC_STATE));
        SftDarkMode_ApplyToDialog(hwndDlg);
        return TRUE;

    case WM_COMMAND:

C++ View entire sample code

    CDialog::OnInitDialog();

    SetIcon(m_hIcon, TRUE);   // Set big icon
    SetIcon(m_hIcon, FALSE);  // Set small icon

    InitStates(m_State, COL_NAME);
    InitStates(m_Abbr, COL_ABBR);
    InitCities();
    m_State.SelectStringExact(-1, COL_NAME, _T("Florida"), FALSE);
    m_Abbr.SelectStringExact(-1, COL_ABBR, _T("FL"), FALSE);
    m_City.SetCurSel(0);
    ShowStatus(m_State);

    // Dark mode
    SftDarkMode_ApplyToDialog(m_hWnd);

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


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