Share via


CListBox::AddString

intAddString(LPCTSTRlpszItem**);**

Return Value

The zero-based index to the string in the list box. The return value is LB_ERR if an error occurs; the return value is LB_ERRSPACE if insufficient space is available to store the new string.

Parameters

lpszItem

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

Remarks

Call this member function to add a string to a list box. If the list box was not created with the LBS_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. If the list box was created with the LBS_SORT style but not the LBS_HASSTRINGS style, the framework sorts the list by one or more calls to the CompareItem member function. 

Use InsertString to insert a string into a specific location within the list box.

Example

// The pointer to my list box.
extern CListBox* pmyListBox;

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

CListBox OverviewClass MembersHierarchy Chart

See Also   CListBox::InsertString, CListBox::CompareItem,