Partilhar via


AddItem Method

Adds a new item to a ComboBox or ListBox control, optionally making it possible for you to specify the item's index.

Control.AddItem(cItem [, nIndex] [, nColumn])

Parameters

  • cItem
    Specifies the string expression to add to the control.

  • nIndex
    Specifies the position where the item is placed in the control. If you supply a valid value for the optional nIndex, cItem is placed at that position within the control. If you specify an nIndex that already exists, the item is inserted at that position and all items below that item are moved down one position in the list portion of the ComboBox or ListBox control.

    If you omit nIndex and the Sorted property is set to True (.T.), cItem is added in alphabetic sort order. If you omit nIndex and the Sorted property is set to False (.F.), cItem is added to the end of the list portion of the ComboBox or ListBox control.

  • nColumn
    Specifies the column of the control to which the new item is added. The default is 1.

Remarks

Use the AddItem method or AddListItem method when the RowSourceType property is set to 0 (None).

Each item added to a ComboBox or ListBox has two identification numbers assigned to it:

  • nItemID, an integer corresponding to the unique ID of the item in the control: the first item corresponds to nItemID = 1 unless another nItemID is specified.
  • nIndex, an integer corresponding to the order in which items are displayed by the control: the first item in the control corresponds to nIndex = 1.

See Also

AddListItem Method | Clear Method | ListIndex Property | ListItemID Property | RowSourceType Property | RemoveItem Method | Sorted Property