method Items.AddItem ([Caption as Variant])

Adds a new item, and returns a handle to the newly created item.

TypeDescription
Caption as Variant A string expression that indicates the caption of the cell on the first column, or a safe array that holds the captions for each column.
ReturnDescription
HITEMA long value that indicates the handle of the newly created item.

Use the AddItem method to add new items to the control. The AddItem method fails, if the control contains no columns. Use the Add method to add new columns to the control. The control fires InsertItem event when a new items is added to the control's list. The Caption parameter indicates the caption of the newly inserted item for the first column. If you have more than a column, you need to use the CellCaption property to assign a caption for each column. The Caption supports built-in HTML format if the CellCaptionFormat property is exHTML. Use InsertItem method to insert a child item.  The InsertItem(,,[Caption]) and AddItem([Caption]) are equivalents. Use the PutItems method to load an array of elements. Use the LockedItemCount property to lock or unlock items to the top or bottom side of the control's list. Use the MergeCells method to combine two or more cells in a single cell. Use the SelectableItem property to specify whether the user can select the item. Use the BeginUpdate and EndUpdate methods to maintain performance while adding new columns and items. Use the ConditionalFormats method to apply formats to a cell or range of cells, and have that formatting change depending on the value of the cell or the value of a formula. The exComputedField type specifies a computed cell.

The following VB sample loads items from a safe array:

With ComboBox1
    .BeginUpdate
    
    .Columns.Add "Column 1"
    .Columns.Add "Column 2"
    .Columns.Add "Column 3"
    
    With .Items
        Dim h As HITEM
        h = .AddItem(Array("Item 1", "Item 2", "Item 3"))
        .InsertItem h, , Array(1, 2, 3)
        .ExpandItem(h) = True
    End With
    
    .EndUpdate
End With

 

The following VB sample adds items to a single column control:

With ComboBox1
    .BeginUpdate
    .ColumnAutoResize = True
    .HeaderVisible = False
    .LinesAtRoot = exLinesAtRoot
    .HasButtons = exCircle
    .Columns.Add "Column 1"
    With .Items
        Dim h As HITEM
        h = .AddItem("Item 1")
        .InsertItem h, , "Item 1.1"
        .InsertItem h, , "Item 1.2"
        .ExpandItem(h) = True
    End With
    .EndUpdate
End With
The following C++ sample adds new items to the control:
#include "Items.h"
CItems items = m_combobox.GetItems();
long iNewItem = items.AddItem( COleVariant( "Item 1" ) );
items.SetCellCaption( COleVariant( iNewItem ), COleVariant( (long)1 ), COleVariant( "SubItem 1" ) );
iNewItem = items.AddItem( COleVariant( "Item 2" ) );
items.SetCellCaption( COleVariant( iNewItem ), COleVariant( (long)1 ), COleVariant( "SubItem 2" ) );

The following VB.NET sample adds new items to the control:

With AxComboBox1.Items
    Dim iNewItem As Integer = .AddItem("Item 1")
    .CellCaption(iNewItem, 1) = "SubItem 1"
    iNewItem = .AddItem("Item 2")
    .CellCaption(iNewItem, 1) = "SubItem 2"
End With

The following C# sample adds new items to the control:

EXCOMBOBOXLib.Items items = axComboBox1.Items;
int iNewItem = items.AddItem( "Item 1" );
items.set_CellCaption( iNewItem, 1, "SubItem 1" );
iNewItem = items.AddItem( "Item 2" );
items.set_CellCaption( iNewItem, 1, "SubItem 2" );

The following VFP sample adds new items to the control:

with thisform.ComboBox1.Items
	.DefaultItem = .AddItem("Item 1")
	.CellCaption(0, 1) = "SubItem 1"
	.DefaultItem = .AddItem("Item 2")
	.CellCaption(0, 1) = "SubItem 2"
endwith