Help Center

CListBox.AddStringmethod

Adds a string to a list box.

WindowsmethodCListBox.incdocumented

Syntax

FUNCTION CListBox.AssString(BYVAL hListBox AS HWND, BYVAL pwszText AS WSTRING PTR) AS LONG

Parameters

NameDescription
hListBoxThe handle of the listbox control.
pwszTextA pointer to the null-terminated string that is to be added.

Return value

The return value is the zero-based index of the string in the list box. If an error occurs, the return value is LB_ERR. If there is insufficient space to store the new string, the return value is LB_ERRSPACE.

Description

Adds a string to a list box. If the list box does not have 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.

Remarks

If the list box has an owner-drawn style and the LBS_SORT style, but not the LBS_HASSTRINGS style, the system sends the WM_COMPAREITEM message one or more times to the owner of the list box to place the new item properly in the list box.

The LB_INITSTORAGE message helps speed up the initialization of list boxes that have a large number of items (more than 100). It reserves the specified amount of memory so that subsequent LB_ADDSTRING messages take the shortest possible time. You can use estimates for the wParam and lParam parameters. If you overestimate, the extra memory is allocated; if you underestimate, the normal allocation is used for items that exceed the requested amount.

If the list box has the WS_HSCROLL style and you add a string wider than the list box, send an LB_SETHORIZONTALEXTENT message to ensure the horizontal scroll bar appears.

Example

CListBox.AddString(hListBox, "New string")

Reference

  • Include file CListBox.inc
  • Defined in AfxNova/CListBox.inc:153
  • Documented in Windows/WIndows Controls/CListBox Class.md
  • Topic: CListBox Class