Select the product you need help with
How to Use Additem and AddListItem and How They Are DifferentArticle ID: 138498 - View products that this article applies to. This article was previously published under Q138498 On This PageSUMMARY
Both the AddItem and AddListItem methods add items to combo boxes or list
boxes. This article highlights their functionality and the differences
between the two methods. In particular, this article demonstrates why the
AddListitem method might be a better way to populate a multiple-column
combo box.
MORE INFORMATION
The Additem and AddlistItem methods add items to a list and accept two
optional parameters. The differences between the two methods are mirrored
in the differences between their first parameter; AddItem accepts
nListIndex as its first parameter, and AddListItem accepts nListItemId
as its first parameter.
There are two ways to identify an item in a list:
The Additem method inserts an item based on its relative position in the list. The syntax is:
Control.AddItem(cItem [, nIndex] [, nColumn])
The AddListItem method allows you to create a unique id for the item, and
uses nItemId. If the item already exists, the prompt is replaced. The
syntax is:
Control.AddListItem(cItem [, nItemID] [, nColumn])
The following example illustrates how to use the Additem and AddListItem
methods. To run the example, copy and paste the code in a program file.
Sample CodeMultiple-Column List BoxesThe AddItem method might not yield expected results when it is used to populate a multiple-column list box. The following step-by-step example illustrates how the elements of a multiple-column list box are displayed when the AddItem method is used.
---------------------
| | Two |
| | Four |
| Three | |
| One | |
---------------------
Use the ListItemId to populate a multiple-column combo box and add items on the same row. By using the example above and replacing AddItem with AddListItem, the list looks like this: ------------------------ | One | Two | | Three | Four | ------------------------ PropertiesArticle ID: 138498 - Last Review: August 10, 1999 - Revision: 1.1
|


Back to the top








