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.

CComboBox::AddString 

Adds a string to the list box of a combo box.


int AddString(
   LPCTSTR lpszString 
);

Parameters

lpszString

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

If the return value is greater than or equal to 0, it is the zero-based index to the string in the list box. 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.

If the list box was not created with the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted.

NoteNote

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

To insert a string into a specific location within the list, use the InsertString member function.

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

// Add 20 items to the combo box.
CString str;
for (int i=0;i < 20;i++)
{
   str.Format(_T("item string %d"), i);
   pmyComboBox->AddString( str );
}

Community Additions

ADD
Show:
© 2015 Microsoft