Dim CP As SAPbouiCOM.FormCreationParams
Dim fTree As SAPbouiCOM.Form
Dim AcXTree As SAPbouiCOM.ActiveX
Dim oItem As SAPbouiCOM.Item
Dim oStatic As SAPbouiCOM.StaticText
Dim oLink As SAPbouiCOM.LinkedButton
' Set the form creation parameters
CP = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)
CP.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Fixed
CP.FormType = "ACXTree"
CP.UniqueID = "ACTree1"
' Add a new form
fTree = SBO_Application.Forms.AddEx(CP)
fTree.Left = 100
fTree.Top = 100
fTree.Width = 300
fTree.Height = 300
fTree.Height = 300
fTree.Title = "TreeView - ActiveX"
' Add the edit text and linked button
oItem = fTree.Items.Add("staticBP", SAPbouiCOM.BoFormItemTypes.it_STATIC)
oItem.Left = 20
oItem.Top = 10
oItem.Width = 200
oStatic = oItem.Specific
oStatic.Caption = "Business Parnters with contacts"
' Add the TreeView Control to the form
oItem = fTree.Items.Add("Tree", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X)
oItem.Left = 20
oItem.Top = 40
oItem.Width = 250
oItem.Height = 200
' Create the new ActiveX control
AcXTree = oItem.Specific
AcXTree.ClassID = "MSComctlLib.TreeCtrl.2"
oTreeView = AcXTree.Object
' Load data to tree nodes
Dim BPNode As MSComctlLib.Node
Dim ContactNode As MSComctlLib.Node
Dim oRecordSet As SAPbobsCOM.Recordset
Dim oBPs As SAPbobsCOM.BusinessPartners
Dim iContact As Integer
' Reference all the Business Partners
oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
oRecordSet.DoQuery("SELECT * FROM OCRD")
oBPs = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners)
oBPs.Browser.Recordset = oRecordSet
' Iterate through all the Business Partners
oBPs.Browser.MoveFirst()
Dim j As Integer
For j = 1 To oBPs.Browser.RecordCount - 1
BPNode = oTreeView.Nodes.Add(, , "B" & oBPs.CardCode, oBPs.CardName)
For iContact = 0 To oBPs.ContactEmployees.Count() - 1
oBPs.ContactEmployees.SetCurrentLine(iContact)
If oBPs.ContactEmployees.Name <> "" Then
ContactNode = oTreeView.Nodes.Add(, , "C" & oBPs.CardCode & iContact.ToString, oBPs.ContactEmployees.Name)
ContactNode.Parent = BPNode
End If
Next iContact
oBPs.Browser.MoveNext()
Next