method Items.InsertItem ([Parent as HITEM], [UserData as Variant], [Caption as Variant])

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

TypeDescription
Parent as HITEM A long expression that indicates the item's handle that indicates the parent item where the newly item is inserted.
UserData as Variant A Variant expression that indicates the item's extra data.
Caption as Variant A string expression that indicates the cell's caption on the first column, a safe array that holds the caption for each column.
ReturnDescription
HITEMRetrieves the handle of the newly created item.

Use the InsertItem property to add a new child item to the specified item. The InsertItem property fires the AddItem event. You can use the InsertItem(,,"Root") or AddItem("Root") to add a root item. An item that has no parent is a root item. 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 the CellCaption property to specify the cell's caption when control contains multiple columns. Use the CellCaptionFormat property to specify whether the cell displays the caption using the HTML format. To insert an ActiveX control, use the InsertControlItem property of the Items property. Use the ExpandItem property to expand an item. Use the MergeCells method to combine two or multiple cells in a single cell. Use the SplitCell property to split a cell. Use the LinesAtRoot property to link items at the root of the hierarchy. 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 following VB sample shows how to create a simple hierarchy:

With Gantt1
    .BeginUpdate
    .ColumnAutoResize = True
    .LinesAtRoot = exLinesAtRoot
    .FullRowSelect = False
    .MarkSearchColumn = False
    .Columns.Add "Default"
    With .Items
        Dim h As HITEM, hx As HITEM
        h = .InsertItem(, , "Root")
        hx = .InsertItem(h, , "This is an item that should break the line")
        .CellSingleLine(hx, 0) = False
        h = .InsertItem(h, , "Child 2")
        .InsertItem h, , "SubChild 2.1"
        h = .InsertItem(h, , "SubChild 2.2")
    End With
    .EndUpdate
End With

The following VB sample insert items and multiple columns as well:

With Gantt1
    .BeginUpdate
    .HeaderVisible = True
    .ColumnAutoResize = True
    .LinesAtRoot = exLinesAtRoot
    .FullRowSelect = False
    .MarkSearchColumn = False
    .Columns.Add "Column 1"
    .Columns.Add "Column 2"
    With .Items
        Dim h As HITEM, hx As HITEM
        h = .InsertItem(, , "Root")
        hx = .InsertItem(h, , Array("This is an item that should break the line", "Just another cell that holds some info"))
        .CellSingleLine(hx, 0) = False
        .CellSingleLine(hx, 1) = False
        h = .InsertItem(h, , "Child 2")
        .InsertItem h, , Array("SubChild 2.1", "SubItem 2.1")
        h = .InsertItem(h, , Array("SubChild 2.2", "SubItem 2.2"))
    End With
    .EndUpdate
End With

The following VB sample inserts a child item and expands the focused item:

With Gantt1.Items
    .InsertItem .FocusItem, , "new child"
    .ExpandItem(.FocusItem) = True
End With

The following C++ sample inserts a child item and expands the focused item:

#include "Items.h"
CItems items = m_gantt.GetItems();
COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
long h = items.InsertItem( items.GetFocusItem(), vtMissing, COleVariant( "new child" ) );
items.SetExpandItem( items.GetFocusItem(), TRUE );

The following VB.NET sample inserts a child item and expands the focused item:

With AxGantt1.Items
    Dim hItem As Integer
    hItem = .InsertItem(.FocusItem, , "new child")
    .ExpandItem(.FocusItem) = True
End With

The following C# sample inserts a child item and expands the focused item:

int hItem = axGantt1.Items.InsertItem(axGantt1.Items.FocusItem, null, "new child");
axGantt1.Items.set_ExpandItem(axGantt1.Items.FocusItem, true);

The following VFP sample inserts a child item and expands the focused item:

with thisform.Gantt1.Items
	.DefaultItem = .InsertItem( .FocusItem, "", "new child" )
	.DefaultItem = .FocusItem
	.ExpandItem(0) = .t.
endwith