method Items.AddItem ([Caption as Variant])

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

   Caption as Variant A string expression that indicates the cell's caption for the first column. or a safe array that contains the captions for each column. The Caption accepts HTML format, if the CellCaptionFormat property is exHTML.  
  HITEMA long expression that indicates the handle of the newly created item. 

Use the Add method to add new columns to the control. If the control contains no columns, the AddItem method fails. Use the AddItem property to add new items to the control. Use the AddBar method to add bars to the item. The bars are always shown in the chart area. Use the PaneWidth property to specify the width of the chart. Use InsertItem method to insert child items to the list. Use the InsertControlItem property to insert and ActiveX control. Use the LockedItemCount property to add or remove items locked to the top or bottom side of the control. Use the MergeCells method to combine two or multiple cells in a single cell. Use the SplitCell property to split a cell. 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. Use the LoadXML/SaveXML methods to load/save the control's data from/to XML files.

The AddItem property adds a new item that has no parent. When a new item is added (inserted) to the Items collection, the control fires the AddItem event. If the control contains more than one column use the CellCaption property to set the cell's caption. If there are no columns AddItem method fails. 

The following VB6 sample uses the VB Array function to add two items: 

With Gantt1
        .Columns.Add "Column 1"
        .Columns.Add "Column 2"
        .Columns.Add "Column 3"
        With .Items
            .AddItem Array("Item 1.1", "Item 1.2", "Item 1.3")
            .AddItem Array("Item 2.1", "Item 2.2", "Item 2.3")
        End With
End With  

In VB/NET using the /NET assembly, the Array equivalent is New Object such as follows:

With Gantt1

    .Columns.Add("Column 1")
    .Columns.Add("Column 2")
    .Columns.Add("Column 3")

    With .Items
        .AddItem(New Object() {"Item 1.1", "Item 1.2", "Item 1.3"})
        .AddItem(New Object() {"Item 2.1", "Item 2.2", "Item 2.3"})
    End With

End With

In C# using the /NET assembly, the Array equivalent is new object such as follows:


exgantt1.Columns.Add("Column 1");
exgantt1.Columns.Add("Column 2");
exgantt1.Columns.Add("Column 3");

exgantt1.Items.AddItem(new object[] { "Item 1.1", "Item 1.2", "Item 1.3" });
exgantt1.Items.AddItem(new object[] { "Item 2.1", "Item 2.2", "Item 2.3" });


Use the PutItems method to load an array, like in the following VB sample:

Set rs = CreateObject("ADODB.Recordset")
rs.Open "Orders", "Provider=Microsoft.Jet.OLEDB.3.51;Data Source= D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", 3 ' Opens the table using static mode
' Add the columns
With Gantt1.Columns
For Each f In rs.Fields
    .Add f.Name
End With
Gantt1.PutItems rs.getRows()

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

#include "Items.h"
CItems items = m_gantt.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 AxGantt1.Items
    Dim iNewItem As Integer
    iNewItem = .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:

EXGANTTLib.Items items = axGantt1.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.Gantt1.Items
	.DefaultItem = .AddItem("Item 1")
	.CellCaption(0, 1) = "SubItem 1"

Send comments on this topic.
1999-2018 Exontrol.COM, Software. All rights reserved.