Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


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

int InsertString(
   int nIndex,
   LPCTSTR lpszString 



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.


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

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.

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


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

// The pointer to my combo box.
extern CComboBox* pmyComboBox;

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

Community Additions

© 2015 Microsoft