HeaderPane
Main
Hide
Share Link
Print

DeleteString

Deletes an item.

C

LONG WINAPI SftBox_DeleteString(HWND hwndCtl, LONG indexTC);

C++

LONG CSftBox::DeleteString(LONG indexTC);

Parameters

hwndCtl

The window handle of the combo box control.

indexTC

Specifies the zero-based index of the item to be deleted.

Returns

The return value is the number of items remaining in the combo box control. The return value is -1 if an error occurred.

Comments

The DeleteString function deletes an item.

If a parent item is deleted, dependents are deleted if the parent item is collapsed (dependents are not visible). If the parent item is expanded when it is deleted, its dependents are not deleted.

If a deletion callback routine has been defined (see SetDeleteCallback), the callback is invoked for each item deleted from the combo box control. This allows application specific cleanup processing to take place for each item.

If the dropdown portion of a dropdown or dropdown list combo box is visible, it is hidden when DeleteString is called. This can be suppressed using SetRollupOnChange.

The WM_SETREDRAW Windows message (CWnd::SetRedraw) can be used to suppress the combo box control from being redrawn when many items are deleted. The use of WM_SETREDRAW is strongly recommended when deleting many items from the combo box control, as it avoids significant processing while items are deleted and drastically reduces the time needed. WM_SETREDRAW (FALSE) should be used once, then all items should be deleted followed by one final WM_SETREDRAW (TRUE) message.

All items can be deleted using ResetContent.

In a combo box control using a virtual data source, this function cannot be used and an error is returned.

Examples

C View entire sample code

        return;

    index = SftBox_FindStringExact(hwndBox, -1, 0, szCity, FALSE);
    if (index > 0)
        index = SftBox_MoveItem(hwndBox, index, 0);
    else if (index < 0) {
        index = SftBox_InsertString(hwndBox, 0, szCity);
        if (SftBox_GetCount(hwndBox) > MAX_HISTORY)
            SftBox_DeleteString(hwndBox, SftBox_GetCount(hwndBox) - 1);
    }
    SftBox_SetCurSel(hwndBox, index);
}

/**********************************************************************/
/*                           Dialog Proc                              */
/**********************************************************************/

C++ View entire sample code

        return;

    index = m_City.FindStringExact(-1, 0, city, FALSE);
    if (index > 0)
        index = m_City.MoveItem(index, 0);
    else if (index < 0) {
        index = m_City.InsertString(0, city);
        if (m_City.GetCount() > MAX_HISTORY)
            m_City.DeleteString(m_City.GetCount() - 1);
    }
    m_City.SetCurSel(index);
}

void CMainDlg::OnOK()
{
    // Enter must not close the sample

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


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