Skip to Content
Former Member
Apr 07, 2008 at 05:14 PM

DataBind and ChooseFromList


Hi All,

I'm developing an add-on where I need to create a new Document.

The Metadata operations were kinda easy, and I'm created (through code) all the UDT, UDF and UDO I needed.

Then I created a form using ScreenPainter, the application Menu and so on.

No I'm just lost with the DataBinding. I'll explain

After loading the form, I bind the form fields to the table were I want to save the information. I do this using DBDataSource and it's working.

If pVal.MenuUID = "OONE_fldOONE_mnuNR" And pVal.BeforeAction = False Then

            BubbleEvent = False
            cSup.LoadFromXML(SBO_Application, "frmNR.srf")

            'Get the added form object by using the form's UID
            oForm = SBO_Application.Forms.Item("frmNR")



            oForm.Items.Item("U_CardCode").Specific.DataBind.SetBound(True, "@OONE_ONR", "U_OONE_CardCode")
            oForm.Items.Item("U_CardCode").Specific.ChooseFromListUID = "CFL1"
            oForm.Items.Item("U_CardCode").Specific.ChooseFromListAlias = "CardCode"
            oForm.Items.Item("cflBut1").Specific.ChooseFromListUID = "CFL3"

            oForm.Items.Item("U_CardName").Specific.DataBind.SetBound(True, "@OONE_ONR", "U_OONE_CardName")
            oForm.Items.Item("U_RefNumb").Specific.DataBind.SetBound(True, "@OONE_ONR", "U_OONE_RefNumb")

But now I need to create some ChooseFromLists, get the next document number and so on. The problem starts with the ChooseFromList. I catch the event, I get the values from the DataTable but I can't set this values to the form fields. I get the "Item - Can't set value on item because the item can't get focus" exception.

I read in the forum that this can be solved by setting the value to the datasource in stead of the item, but how can I do this?

I've also tried to use UserDataSources but I can't get it to work...

Can someone provide me an example on how to create a new B1 Document?

Or can someone take a look at my code and point out what I'm doing wrong?

 Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent

        Select Case pVal.EventType
                'Tratar eventos do tipo ChooseFromList
            Case SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST

                'Se estamos presente o formulário "Nota de Recepção" e o item é o "U_CardCode"
                If FormUID = "frmNR" And (pVal.ItemUID = "U_CardCode" Or pVal.ItemUID = "cflBut1") Then

                    Dim oCFLEvent As SAPbouiCOM.IChooseFromListEvent = pVal
                    Dim sCFL_ID As String = oCFLEvent.ChooseFromListUID
                    Dim oCFL As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Item(sCFL_ID)

                    Dim oDataTable As SAPbouiCOM.DataTable = oCFLEvent.SelectedObjects
                    Dim CardCode As String
                    Dim CardName As String = ""

                    If oCFLEvent.BeforeAction = False Then
                            CardCode = oDataTable.GetValue("CardCode", 0)
                            CardName = oDataTable.GetValue("CardName", 0)
                            ' oForm.DataSources.UserDataSources.Item("U_CardCode").ValueEx = CardCode
                            oForm.Items.Item("U_CardCode").Specific.Value = CardCode
                            oForm.Items.Item("U_CardName").Specific.Value = CardName
                        Catch ex As Exception
                        End Try
                    End If
                End If

My Form



Thanks in advanced.

Best Regards,

Vitor Vieira