event AddItem (Item as HITEM)

Occurs after a new Item has been inserted to Items collection.

TypeDescription
Item as HITEM A long expression that indicates the handle of the item that's inserted to the Items collection.

The AddItem event notifies your application that a new items is inserted. Use the AddItem and InsertItem methods to insert new items to Items collection. Use the InsertControlItem method to add a new item that hosts an ActiveX control. Use the Add method to add new columns to Columns Collection. Use the Def property to specify a common value for all cells in the same column.

Syntax for AddItem event, /NET version, on:

private void AddItem(object sender,int Item)
{
}

Private Sub AddItem(ByVal sender As System.Object,ByVal Item As Integer) Handles AddItem
End Sub

Syntax for AddItem event, /COM version, on:

private void AddItem(object sender, AxEXGANTTLib._IGanttEvents_AddItemEvent e)
{
}

void OnAddItem(long Item)
{
}

void __fastcall AddItem(TObject *Sender,Exganttlib_tlb::HITEM Item)
{
}

procedure AddItem(ASender: TObject; Item : HITEM);
begin
end;

procedure AddItem(sender: System.Object; e: AxEXGANTTLib._IGanttEvents_AddItemEvent);
begin
end;

begin event AddItem(long Item)
end event AddItem

Private Sub AddItem(ByVal sender As System.Object, ByVal e As AxEXGANTTLib._IGanttEvents_AddItemEvent) Handles AddItem
End Sub

Private Sub AddItem(ByVal Item As EXGANTTLibCtl.HITEM)
End Sub

Private Sub AddItem(ByVal Item As Long)
End Sub

LPARAMETERS Item

PROCEDURE OnAddItem(oGantt,Item)
RETURN

Syntax for AddItem event, /COM version (others), on:

<SCRIPT EVENT="AddItem(Item)" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function AddItem(Item)
End Function
</SCRIPT>

Procedure OnComAddItem HITEM llItem
	Forward Send OnComAddItem llItem
End_Procedure

METHOD OCX_AddItem(Item) CLASS MainDialog
RETURN NIL

void onEvent_AddItem(int _Item)
{
}

function AddItem as v (Item as OLE::Exontrol.Gantt.1::HITEM)
end function

function nativeObject_AddItem(Item)
return

The following VB sample shows how to change the item's foreground color:

Private Sub Gantt1_AddItem(ByVal Item As EXGANTTLibCtl.HITEM)
    Gantt1.Items.ItemForeColor(Item) = vbBlue
End Sub

The following VB sample changes the background color for all cells in the first column:

Gantt1.Columns(0).Def(exCellBackColor) = RGB(240, 240, 240)

The following C++ sample changes the item's foreground color when a new items is inserted:

#include "Items.h"
void OnAddItemGantt1(long Item) 
{
	if ( ::IsWindow( m_gantt.m_hWnd ) )
	{
		CItems items = m_gantt.GetItems();
		items.SetItemForeColor( Item, RGB(0,0,255) );
	}
}

The following C++ sample changes the background color for all cells in the first column:

COleVariant vtBackColor( (long)RGB(240, 240, 240) );
m_gantt.GetColumns().GetItem( COleVariant( (long) 0 ) ).SetDef( /*exCellBackColor*/ 4, vtBackColor );

The following VB.NET sample changes the item's foreground color when a new items is inserted:

Shared Function ToUInt32(ByVal c As Color) As UInt32
    Dim i As Long
    i = c.R
    i = i + 256 * c.G
    i = i + 256 * 256 * c.B
    ToUInt32 = Convert.ToUInt32(i)
End Function

Private Sub AxGantt1_AddItem(ByVal sender As System.Object, ByVal e As AxEXGANTTLib._IGanttEvents_AddItemEvent) Handles AxGantt1.AddItem
    AxGantt1.Items.ItemForeColor(e.item) = ToUInt32(Color.Blue)
End Sub

The following VB.NET sample changes the background color for all cells in the first column:

With AxGantt1.Columns(0)
    .Def(EXGANTTLib.DefColumnEnum.exCellBackColor) = ToUInt32(Color.WhiteSmoke)
End With

The following C# sample changes the item's foreground color when a new items is inserted:

private UInt32 ToUInt32(Color c)
{
	long i;
	i = c.R;
	i = i + 256 * c.G;
	i = i + 256 * 256 * c.B;
	return Convert.ToUInt32(i);
}

private void axGantt1_AddItem(object sender, AxEXGANTTLib._IGanttEvents_AddItemEvent e)
{
	axGantt1.Items.set_ItemForeColor( e.item, ToUInt32(Color.Blue) );
}

The following C# sample changes the background color for all cells in the first column:

axGantt1.Columns[0].set_Def(EXGANTTLib.DefColumnEnum.exCellBackColor, ToUInt32(Color.WhiteSmoke));

The following VFP sample changes the item's foreground color when a new items is inserted:

*** ActiveX Control Event ***
LPARAMETERS item

with thisform.Gantt1.Items
	.DefaultItem = item
	.ItemForeColor( 0 ) = RGB(0,0,255 )
endwith

The following VFP sample changes the background color for all cells in the first column:

with thisform.Gantt1.Columns(0)
	.Def( 4 ) = RGB(240,240,240)
endwith

For instance, the following VB sample loads an ADO recordset.

Dim rs As Object

Private Sub Form_Load()

    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

    Gantt1.BeginUpdate
    ' Add the columns
    With Gantt1.Columns
    For Each f In rs.Fields
        .Add f.Name
    Next
    End With

    ' Add the items
    With Gantt1.Items
    rs.MoveFirst
    While Not rs.EOF
        .InsertItem , rs.Bookmark
        rs.MoveNext
    Wend
End With

    Gantt1.EndUpdate
End Sub

Private Sub Gantt1_AddItem(ByVal Item As EXGANTTLibCtl.HITEM)
    Dim i As Integer
    Dim n As Integer
    n = Gantt1.Columns.Count
    With Gantt1.Items
    For i = 0 To n - 1
        .CellCaption(Item, i) = rs(i).Value
    Next
    End With
End Sub

The following VB sample use the PutItems method to load items to the control:

Dim rs As Object

Private Sub Form_Load()

    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

    Gantt1.BeginUpdate
    ' Add the columns
    With Gantt1.Columns
    For Each f In rs.Fields
        .Add f.Name
    Next
    End With

    Gantt1.PutItems rs.getRows()

    Gantt1.EndUpdate
End Sub