event InsertItem (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 newly inserted item.  

The InsertItem event notifies your application that a new item is inserted. Use the InsertItem event to associate extra data to the item.  The InsertItem event is fired when PutItems, AddItem or InsertItem property of the Items object is called. Use the Add method to add new columns to Columns Collection. Use the Def property to specify a common property for all cells in the same column. 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.

The following VB sample changes the foreground and background colors for cells in the first column, as soon as they are inserted:

Private Sub ComboBox1_InsertItem(ByVal Item As EXCOMBOBOXLibCtl.HITEM)
    With ComboBox1.Items
        .CellBackColor(Item, 0) = vbBlue
        .CellForeColor(Item, 0) = vbWhite
    End With
End Sub

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

With ComboBox1.Columns(0)
    .Def(exCellBackColor) = RGB(240, 240, 240)
End With

The following C++ sample changes the foreground and background colors for cells in the first column, as soon as they are inserted:

#include "Items.h"
void OnInsertItemCombobox1(long Item) 
{
	if ( IsWindow( m_combobox.m_hWnd ) )
	{
		CItems items = m_combobox.GetItems();
		COleVariant vtItem( Item ), vtColumn( long(0) );
		items.SetCellBackColor( vtItem, vtColumn, RGB(0,0,255) );
		items.SetCellForeColor( vtItem, vtColumn, RGB(255,255,255) );
	}
}

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

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

The following VB.NET sample changes the foreground and background colors for cells in the first column, as soon as they are inserted:

Private Sub AxComboBox1_InsertItem(ByVal sender As System.Object, ByVal e As AxEXCOMBOBOXLib._IComboBoxEvents_InsertItemEvent) Handles AxComboBox1.InsertItem
    With AxComboBox1.Items
        .CellBackColor(e.item, 0) = ToUInt32(Color.Blue)
        .CellForeColor(e.item, 0) = ToUInt32(Color.White)
    End With
End Sub

where the ToUInt32 function converts a Color expression to an OLE_COLOR expression,

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

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

With AxComboBox1.Columns(0)
    .Def(EXCOMBOBOXLib.DefColumnEnum.exCellBackColor) = ToUInt32(Color.WhiteSmoke)
End With

The following C# sample changes the foreground and background colors for cells in the first column, as soon as they are inserted:

private void axComboBox1_InsertItem(object sender, AxEXCOMBOBOXLib._IComboBoxEvents_InsertItemEvent e)
{
	EXCOMBOBOXLib.Items items = axComboBox1.Items;
	items.set_CellBackColor(e.item, 0, ToUInt32(Color.Blue));
	items.set_CellForeColor(e.item, 0, ToUInt32(Color.White));
}

where the ToUInt32 function converts a Color expression to an OLE_COLOR expression,

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);
}

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

axComboBox1.Columns[0].set_Def(EXCOMBOBOXLib.DefColumnEnum.exCellBackColor, ToUInt32(Color.WhiteSmoke));

The following VFP sample changes the foreground and background colors for cells in the first column, as soon as they are inserted:

*** ActiveX Control Event ***
LPARAMETERS item

with thisform.ComboBox1.Items
	.DefaultItem = item
	.CellBackColor(0,0) = RGB(0,0,255)
	.CellForeColor(0,0) = RGB(255,255,255)
endwith

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

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

Syntax for InsertItem event, /NET version, on:

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

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

Syntax for InsertItem event, /COM version, on:

private void InsertItem(object sender, AxEXCOMBOBOXLib._IComboBoxEvents_InsertItemEvent e)
{
}

void OnInsertItem(long Item)
{
}

void __fastcall InsertItem(TObject *Sender,Excomboboxlib_tlb::HITEM Item)
{
}

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

procedure InsertItem(sender: System.Object; e: AxEXCOMBOBOXLib._IComboBoxEvents_InsertItemEvent);
begin
end;

begin event InsertItem(long Item)
end event InsertItem

Private Sub InsertItem(ByVal sender As System.Object, ByVal e As AxEXCOMBOBOXLib._IComboBoxEvents_InsertItemEvent) Handles InsertItem
End Sub

Private Sub InsertItem(ByVal Item As EXCOMBOBOXLibCtl.HITEM)
End Sub

Private Sub InsertItem(ByVal Item As Long)
End Sub

LPARAMETERS Item

PROCEDURE OnInsertItem(oComboBox,Item)
RETURN

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

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

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

Procedure OnComInsertItem HITEM llItem
	Forward Send OnComInsertItem llItem
End_Procedure

METHOD OCX_InsertItem(Item) CLASS MainDialog
RETURN NIL

void onEvent_InsertItem(int _Item)
{
}

function InsertItem as v (Item as OLE::Exontrol.ComboBox.1::HITEM)
end function

function nativeObject_InsertItem(Item)
return


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