Inserts a new item of ActiveX type, and returns a handle to the newly created item.
Type | Description | |||
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. |
Return | Description | |||
HITEM | A long expression that indicates the handle of the newly created item. |
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 exTree control.
Use the ItemHeight property to specify the height of the item when it contains an ActiveX control. Use the ItemWidth property to specify the width of the ActiveX control, or the position in the item where the ActiveX is displayed. 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 exTree 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 Tree1 .BeginUpdate .ScrollBySingleLine = True With Tree1.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_tree.GetItems(); m_tree.BeginUpdate(); m_tree.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_tree.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 ExTree Component:
axTree1.BeginUpdate(); EXTREELib.Items items = axTree1.Items; axTree1.ScrollBySingleLine = true; int h = items.InsertControlItem(0, "Exontrol.Tree",""); items.set_ItemHeight(h, 182); object treeInside = items.get_ItemObject(h); if ( treeInside != null ) { EXTREELib.Tree tree = treeInside as EXTREELib.Tree; if (tree != null) { tree.BeginUpdate(); tree.LinesAtRoot = EXTREELib.LinesAtRootEnum.exLinesAtRoot; tree.Columns.Add("Column 1"); tree.Columns.Add("Column 2"); tree.Columns.Add("Column 3"); EXTREELib.Items itemsInside = tree.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"); tree.EndUpdate(); } } axTree1.EndUpdate();
The following VB.NET sample adds the Exontrol's ExOrgChart Component:
With AxTree1 .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.Tree1 .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 ExTree ActiveX Control and a Microsoft Calendar Control:
' Inserts a new ActiveX control of Exontrol.Tree type Dim hTree As HITEM hTree = Tree1.Items.InsertControlItem(Tree1.Items(0), "Exontrol.Tree", runtimelicensekey ) ' Sets the ActiveX control height Tree1.Items.ItemHeight(hTree) = 212 ' Gets the ExTree control created. Since the ProgID used to create the item is "Exontrol.Tree" ' the object will be of EXTREELibCtl.Tree type Dim objTree As Object Set objTree = Tree1.Items.ItemObject(hTree) objTree.Columns.Add "Column" objTree.Items.AddItem "One" objTree.Items.AddItem "Two" objTree.Items.AddItem "Three" ' Inserts a new ActiveX control of MSCAL.Calendar type Dim hCalc As HITEM hCalc = objTree.Items.InsertControlItem(, "MSCal.Calendar") Set objCalc = Tree1.Items.ItemObject(hCalc) objCalc.ShowTitle = False objCalc.ShowDateSelectors = False
where the runtimelicensekey is the exTree's runtime license key. Please contact us to get the exTree'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 Tree1_ItemOleEvent(ByVal Item As EXTREELibCtl.HITEM, ByVal Ev As EXTREELibCtl.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 Tree1.Items.InsertControlItem(, "https://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 = Tree1.Items.InsertControlItem(, "https://www.exontrol.com") Tree1.Items.ItemHeight(hWeb) = 196
Next step is adding the AddItem event handler:
Private Sub Tree1_AddItem(ByVal Item As EXTREELibCtl.HITEM) If (Tree1.Items.ItemControlID(Item) = "https://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 Tree1.Items.ItemWindowHostCreateStyle(Item) = Tree1.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"