Occurs after a new Item has been inserted to Items collection.
![]() | Type | Description | ||
| 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.
The following VB sample shows how to change the item's foreground color:
Private Sub G2antt1_AddItem(ByVal Item As EXG2ANTTLibCtl.HITEM) G2antt1.Items.ItemForeColor(Item) = vbBlue End Sub
The following VB sample changes the background color for all cells in the first column:
G2antt1.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 OnAddItemG2antt1(long Item)
{
if ( ::IsWindow( m_g2antt.m_hWnd ) )
{
CItems items = m_g2antt.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_g2antt.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 AxG2antt1_AddItem(ByVal sender As System.Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_AddItemEvent) Handles AxG2antt1.AddItem
AxG2antt1.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 AxG2antt1.Columns(0)
.Def(EXG2ANTTLib.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 axG2antt1_AddItem(object sender, AxEXG2ANTTLib._IG2anttEvents_AddItemEvent e)
{
axG2antt1.Items.set_ItemForeColor( e.item, ToUInt32(Color.Blue) );
}
The following C# sample changes the background color for all cells in the first column:
axG2antt1.Columns[0].set_Def(EXG2ANTTLib.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.G2antt1.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.G2antt1.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
G2antt1.BeginUpdate
' Add the columns
With G2antt1.Columns
For Each f In rs.Fields
.Add f.Name
Next
End With
' Add the items
With G2antt1.Items
rs.MoveFirst
While Not rs.EOF
.InsertItem , rs.Bookmark
rs.MoveNext
Wend
End With
G2antt1.EndUpdate
End Sub
Private Sub G2antt1_AddItem(ByVal Item As EXG2ANTTLibCtl.HITEM)
Dim i As Integer
Dim n As Integer
n = G2antt1.Columns.Count
With G2antt1.Items
For i = 0 To n - 1
.CellValue(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
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
End Sub