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, AxEXTREELib._ITreeEvents_AddItemEvent e)
{
}

void OnAddItem(long Item)
{
}

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

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

procedure AddItem(sender: System.Object; e: AxEXTREELib._ITreeEvents_AddItemEvent);
begin
end;

begin event AddItem(long Item)
end event AddItem

Private Sub AddItem(ByVal sender As System.Object, ByVal e As AxEXTREELib._ITreeEvents_AddItemEvent) Handles AddItem
End Sub

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

Private Sub AddItem(ByVal Item As Long)
End Sub

LPARAMETERS Item

PROCEDURE OnAddItem(oTree,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.Tree.1::HITEM)
end function

function nativeObject_AddItem(Item)
return

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

Private Sub Tree1_AddItem(ByVal Item As EXTREELibCtl.HITEM)
    Tree1.Items.ItemForeColor(Item) = vbBlue
End Sub

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

Tree1.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 OnAddItemTree1(long Item) 
{
	if ( ::IsWindow( m_tree.m_hWnd ) )
	{
		CItems items = m_tree.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_tree.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 AxTree1_AddItem(ByVal sender As System.Object, ByVal e As AxEXTREELib._ITreeEvents_AddItemEvent) Handles AxTree1.AddItem
    AxTree1.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 AxTree1.Columns(0)
    .Def(EXTREELib.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 axTree1_AddItem(object sender, AxEXTREELib._ITreeEvents_AddItemEvent e)
{
	axTree1.Items.set_ItemForeColor( e.item, ToUInt32(Color.Blue) );
}

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

axTree1.Columns[0].set_Def(EXTREELib.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.Tree1.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.Tree1.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

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

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

    Tree1.EndUpdate
End Sub

Private Sub Tree1_AddItem(ByVal Item As EXTREELibCtl.HITEM)
    Dim i As Integer
    Dim n As Integer
    n = Tree1.Columns.Count
    With Tree1.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

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

    Tree1.PutItems rs.getRows()

    Tree1.EndUpdate
End Sub

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