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 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 CellValueFormat property is exHTML, or a formula if the CellValueFormat property is exComputedField.  
 ReturnDescription 
  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 LoadXML/SaveXML methods to load/save the control's data from/to XML files. Use the AddItem property to add new items to the control. Use the AddBar method to add bars to the item. Use the AddLink method to link a bar with another. 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 FormatColumn property to format the column.

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 CellValue 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 G2antt1
    .BeginUpdate
    
        .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
        
    .EndUpdate
End With  

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

With G2antt1
    .BeginUpdate()

    .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

    .EndUpdate()
End With

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

exg2antt1.BeginUpdate();

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

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

exg2antt1.EndUpdate();

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
G2antt1.BeginUpdate
' Add the columns
With G2antt1.Columns
For Each f In rs.Fields
    .Add f.Name
Next
End With
G2antt1.PutItems rs.getRows()
G2antt1.EndUpdate

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

#include "Items.h"
CItems items = m_g2antt.GetItems();
long iNewItem = items.AddItem( COleVariant( "Item 1" ) );
items.SetCellValue( COleVariant( iNewItem ), COleVariant( (long)1 ), COleVariant( "SubItem 1" ) );
iNewItem = items.AddItem( COleVariant( "Item 2" ) );
items.SetCellValue( COleVariant( iNewItem ), COleVariant( (long)1 ), COleVariant( "SubItem 2" ) );

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

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

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

EXG2ANTTLib.Items items = axG2antt1.Items;
int iNewItem = items.AddItem( "Item 1" );
items.set_CellValue( iNewItem, 1, "SubItem 1" );
iNewItem = items.AddItem( "Item 2" );
items.set_CellValue( iNewItem, 1, "SubItem 2" );

The following VFP sample adds new items to the control:

with thisform.G2antt1.Items
	.DefaultItem = .AddItem("Item 1")
	.CellValue(0, 1) = "SubItem 1"
endwith

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