Partager via


CListBox::AddString

Adds a string to a list box.

int AddString(
   LPCTSTR lpszItem 
);

Parameters

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

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.

Remarks

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

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

Requirements

Header: afxwin.h

See Also

Reference

CListBox Class

Hierarchy Chart

CListBox::InsertString

CListBox::CompareItem

LB_ADDSTRING

Other Resources

CListBox Members