📚 SAP Business One SDK Help

ActiveX Object
See Also  Members  Example

Description

Represents an ActiveX object.

Remarks

The UI API does not support ActiveX objects written in Visual Basic 6.0.

Example

Using an ActiveX object (Visual Basic)Copy Code
Private Sub CreateFormWithActiveX()

    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"

    oItem = fTree.Items.Add("txtBP", SAPbouiCOM.BoFormItemTypes.it_EDIT)
    oItem.Left = 20
    oItem.Top = 250
    oItem.Width = 60
    oEdit = oItem.Specific

    oItem = fTree.Items.Add("BPLink", SAPbouiCOM.BoFormItemTypes.it_LINKED_BUTTON)
    oItem.Left = 80
    oItem.Top = 250
    oItem.LinkTo = "txtBP"
    oLink = oItem.Specific
    oLink.LinkedObject = SAPbouiCOM.BoLinkedObject.lf_BusinessPartner

    ' 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

      ' Make the form visible
      fTree.Visible = True

End Sub

See Also