method Items.InsertControlItem (Parent as HITEM, ControlID as String, [License as Variant])

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

 TypeDescription 
   Parent as HITEM A long expression that indicates the handle of the parent item where the ActiveX will be inserted. If the argument is missing then the InsertControlItem property inserts the ActiveX control as a root item. If the Parent property is referring a locked item  ( ItemLocked property ), the InsertControlItem property doesn't insert a new child ActiveX, instead insert the ActiveX control to the locked item that's specified by the Parent property.  
   ControlID as String A string expression that can be formatted as follows: a prog ID, a CLSID, a URL, a reference to an Active document , a fragment of HTML.  
   License as Variant A string expression that indicates the runtime license key, if it is required. An empty string, if the control doesn't require a runtime license key.  
 ReturnDescription 
  HITEMA long expression that indicates the handle of the newly created 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.  The control supports ActiveX hosting, so you can insert any ActiveX component. The ControlID must be formatted in one of the following ways:

The InsertControlItem property creates an ActiveX control that's hosted by the exGrid control. The look and feel of the inner ActiveX control depends on the identifier you are using, and the version of the library that implements the ActiveX control, so you need to consult the documentation of the inner ActiveX control you are inserting inside the exGantt control.

Once that an item of ActiveX type has been added you can get the OLE control created using the ItemObject property. To check if an item contains an ActiveX control you can use ItemControlID property. To change the height of an ActiveX item you have to use ItemHeight property. When the control contains at least an item of ActiveX type, it is recommended to set ScrollBySingleLine property of control to true.  Events from contained components are fired through to your program using the exact same model used in VB6 for components added at run time ( See ItemOleEvent event, OleEvent and OleEventParam ). For instance, when an ActiveX control fires an event, the control forwards that event to your container using ItemOleEvent event of the exGantt control. Use the ItemObject property to access the object being created by the InsertControlItem property. Use the ItemHeight property to specify the height of the item when containing an ActiveX control. Use the ItemWidth property to specify the width of the ActiveX control. Use the BeginUpdate and EndUpdate methods to update the control's content when adding ActiveX controls on the fly. Use the ItemControlID property to retrieve the control's identifier.

The following VB sample adds the Exontrol's ExCalendar Component:

With Gantt1
    .BeginUpdate
    .ScrollBySingleLine = True
    With Gantt1.Items
        Dim h As HITEM
        h = .InsertControlItem(, "Exontrol.Calendar")
        .ItemHeight(h) = 182
        With .ItemObject(h)
            .Appearance = 0
            .BackColor = vbWhite
            .ForeColor = vbBlack
            .ShowTodayButton = False
        End With
    End With
    .EndUpdate
End With

The following C++ sample adds the Exontrol's ExOrgChart Component:

#include "Items.h"

#pragma warning( disable : 4146 )
#import <ExOrgChart.dll> 

CItems items = m_gantt.GetItems();
m_gantt.BeginUpdate();
m_gantt.SetScrollBySingleLine( TRUE );
COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
long h = items.InsertControlItem( 0, "Exontrol.ChartView", vtMissing );
items.SetItemHeight( h, 182 );
EXORGCHARTLib::IChartViewPtr spChart( items.GetItemObject(h) );
if ( spChart != NULL )
{
	spChart->BeginUpdate();
	spChart->BackColor = RGB(255,255,255);
	spChart->ForeColor = RGB(0,0,0);
	EXORGCHARTLib::INodesPtr spNodes = spChart->Nodes;
	spNodes->Add( "Child 1", "Root", "1", vtMissing, vtMissing );
	spNodes->Add( "SubChild 1", "1", vtMissing, vtMissing, vtMissing );
	spNodes->Add( "SubChild 2", "1", vtMissing, vtMissing, vtMissing );
	spNodes->Add( "Child 2", "Root", vtMissing, vtMissing, vtMissing );
	spChart->EndUpdate();
}
m_gantt.EndUpdate();

The sample uses the #import statement to include the ExOrgChart's Type Library. In this sample, the ItemObject property retrieves an IChartView object. The path to the library should be provided in case it is not located in your system folder.  

The following C# sample adds the Exontrol's ExGantt Component:

axGantt1.BeginUpdate();
EXGANTTLib.Items items = axGantt1.Items;
axGantt1.ScrollBySingleLine = true;
int h = items.InsertControlItem(0, "Exontrol.Gantt","");
items.set_ItemHeight(h, 182);
object ganttInside = items.get_ItemObject(h);
if ( ganttInside != null )
{
	EXGANTTLib.Gantt gantt = ganttInside as EXGANTTLib.Gantt;
	if (gantt != null)
	{
		gantt.BeginUpdate();
		gantt.LinesAtRoot = EXGANTTLib.LinesAtRootEnum.exLinesAtRoot;
		gantt.Columns.Add("Column 1");
		gantt.Columns.Add("Column 2");
		gantt.Columns.Add("Column 3");
		EXGANTTLib.Items itemsInside = gantt.Items;
		int hInside = itemsInside.AddItem("Item 1");
		itemsInside.set_CellCaption(hInside, 1, "SubItem 1");
		itemsInside.set_CellCaption(hInside, 2, "SubItem 2");
		hInside = itemsInside.InsertItem(hInside, null, "Item 2");
		itemsInside.set_CellCaption(hInside, 1, "SubItem 1");
		itemsInside.set_CellCaption(hInside, 2, "SubItem 2");
		gantt.EndUpdate();
	}
}
axGantt1.EndUpdate();

The following VB.NET sample adds the Exontrol's ExOrgChart Component:

With AxGantt1
    .BeginUpdate()
    .ScrollBySingleLine = True
    With .Items
        Dim hItem As Integer
        hItem = .InsertControlItem(, "Exontrol.ChartView")
        .ItemHeight(hItem) = 182
        With .ItemObject(hItem)
            .BackColor = ToUInt32(Color.White)
            .ForeColor = ToUInt32(Color.Black)
            With .Nodes
                .Add("Child 1", , "1")
                .Add("SubChild 1", "1")
                .Add("SubChild 2", "1")
                .Add("Child 2")
            End With
        End With
    End With
    .EndUpdate()
End With

The following VFP sample adds the Exontrol's ExGrid Component:

with thisform.Gantt1
	.BeginUpdate()
	.ScrollBySingleLine = .t.
	with .Items
		.DefaultItem = .InsertControlItem(0, "Exontrol.Grid")
		.ItemHeight( 0 ) = 182
		with .ItemObject( 0 )
			.BeginUpdate()
			with .Columns
				with .Add("Column 1").Editor()
					.EditType = 1 && EditType editor
				endwith
			endwith
			with .Items
				.AddItem("Text 1")
				.AddItem("Text 2")
				.AddItem("Text 3")
			endwith
			.EndUpdate()
		endwith
	endwith
	.EndUpdate()
endwith

The following VB sample adds dynamically an ExGantt ActiveX Control and a Microsoft Calendar Control:

' Inserts a new ActiveX control of Exontrol.Gantt type
Dim hGantt As HITEM
hGantt = Gantt1.Items.InsertControlItem(Gantt1.Items(0), "Exontrol.Gantt", runtimelicensekey )
' Sets the ActiveX control height
Gantt1.Items.ItemHeight(hGantt) = 212
' Gets the ExGantt control created. Since the ProgID used to create the item is "Exontrol.Gantt"
' the object will be of EXGANTTLibCtl.Gantt type
Dim objGantt As Object
Set objGantt = Gantt1.Items.ItemObject(hGantt)
objGantt.Columns.Add "Column"
objGantt.Items.AddItem "One"
objGantt.Items.AddItem "Two"
objGantt.Items.AddItem "Three"

' Inserts a new ActiveX control of MSCAL.Calendar type
Dim hCalc As HITEM
hCalc = objGantt.Items.InsertControlItem(, "MSCal.Calendar")
Set objCalc = Gantt1.Items.ItemObject(hCalc)
objCalc.ShowTitle = False
objCalc.ShowDateSelectors = False

where the runtimelicensekey is the exGantt's runtime license key. Please contact us to get the exGantt's runtime license key. Please notice that your development license key is not equivalent with the generated runtime license key. Your order number is required, when requesting the control's runtime license key. If you are using the DEMO version for testing purpose, you don't need a runtime license key. 

The following VB sample handles any event that a contained ActiveX fires:

Private Sub Gantt1_ItemOleEvent(ByVal Item As EXGANTTLibCtl.HITEM, ByVal Ev As EXGANTTLibCtl.IOleEvent)
    On Error Resume Next
    Dim i As Long
    Debug.Print "The " & Ev.Name & " was fired. "
    If Not (Ev.CountParam = 0) Then
        Debug.Print "The event has the following parameters: "
        For i = 0 To Ev.CountParam - 1
            Debug.Print " - " & Ev(i).Name & " = " & Ev(i).Value
        Next
    End If
End Sub

Some of ActiveX controls requires additional window styles to be added to the conatiner window. For instance, the Web Brower added by the Gantt1.Items.InsertControlItem(, "http://www.exontrol.com") won't add scroll bars, so you have to do the following:

First thing is to declare the WS_HSCROLL and WS_VSCROLL constants at the top of your module:

Private Const WS_VSCROLL = &H200000
Private Const WS_HSCROLL = &H100000

Then you need to to insert a Web control use the following lines:

Dim hWeb As HITEM
hWeb = Gantt1.Items.InsertControlItem(, "http://www.exontrol.com")
Gantt1.Items.ItemHeight(hWeb) = 196

Next step is adding the AddItem event handler:

Private Sub Gantt1_AddItem(ByVal Item As EXGANTTLibCtl.HITEM)
    If (Gantt1.Items.ItemControlID(Item) = "http://www.exontrol.com") Then
        ' Some of controls like the WEB control, requires some additional window styles ( like WS_HSCROLL and WS_VSCROLL window styles )
        ' for the window that host that WEB control, to allow scrolling the web page
        Gantt1.Items.ItemWindowHostCreateStyle(Item) = Gantt1.Items.ItemWindowHostCreateStyle(Item) + WS_HSCROLL + WS_VSCROLL
    End If
End Sub

If somehow the InsertItemControl wasn't able to create your ActiveX on some Windows platforms, and you don't know why, you can use the following

code to make sure that ActiveX control can be created properly by using ( the sample is trying to add a new Microsoft RichText ActivX control into your form):

Controls.Add "RICHTEXT.RichtextCtrl", "rich"

ItemOLEEvent2.jpg (22680 bytes)InsertControlItem.jpg (25384 bytes)

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