Article ID: 138498 - View products that this article applies to.
This article was previously published under Q138498
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.
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.
Multiple-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.
This occurs because the AddItem inserts each item at the relative position specified by the nIndex integer.
--------------------- | | 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:
For more information about the AddItem and AddListItem methods, search for "AddItem" or "AddListItem" in the Visual FoxPro Help file.
------------------------ | One | Two | | Three | Four | ------------------------
Article ID: 138498 - Last Review: August 10, 1999 - Revision: 1.1