Condividi tramite


CComboBox::InsertString

Inserts a string into the list box of a combo box.

int InsertString(
   int nIndex,
   LPCTSTR lpszString 
);

Parameters

  • nIndex
    Contains the zero-based index to the position in the list box that will receive the string. If this parameter is –1, the string is added to the end of the list.

  • lpszString
    Points to the null-terminated string that is to be inserted.

Return Value

The zero-based index of the position at which the string was inserted. The return value is CB_ERR if an error occurs. The return value is CB_ERRSPACE if insufficient space is available to store the new string.

Remarks

Unlike the AddString member function, the InsertString member function does not cause a list with the CBS_SORT style to be sorted.

Nota

This function is not supported by the Windows ComboBoxEx control. For more information on this control, see ComboBoxEx Controls in the Windows SDK.

Example

// Insert items in between existing items.
CString strIns;
int nItems = m_pComboBox->GetCount();
for (int i = 0; i < nItems; i++)
{
   strIns.Format(_T("item string %c"), (char)('A'+i));
   m_pComboBox->InsertString(2*i, strIns);
}

Requirements

Header: afxwin.h

See Also

Reference

CComboBox Class

Hierarchy Chart

CComboBox::AddString

CComboBox::DeleteString

CComboBox::ResetContent

CB_INSERTSTRING

Other Resources

CComboBox Members