Skip to Content
avatar image
Former Member

Return Code , Name using ChooseList

Hi

  Below is the code . I want when user select Code it should return Name also

Private Sub DrawAddForm(ByVal oForm As SAPbouiCOM.Form)

        Dim oItem As SAPbouiCOM.Item

        Dim oLabel As SAPbouiCOM.StaticText

        Dim oEdit As SAPbouiCOM.EditText

        Dim oButton As SAPbouiCOM.Button

        Dim oStatic As SAPbouiCOM.StaticText

        oForm0.Top = 150

        oForm0.Left = 330

        oForm0.ClientWidth = 200

        oForm0.ClientHeight = 170

        oForm0.Title = "Maintain Transaction"

        oForm0.DataSources.UserDataSources.Add("EditDS", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)

AddChooseFromList()

        oItem = oForm0.Items.Add("EditTxt", SAPbouiCOM.BoFormItemTypes.it_EDIT)

        oItem.Left = 100

        oItem.Top = 10

        oItem.LinkTo = "StaticTxt"

        oEdit = oItem.Specific

        oItem = oForm0.Items.Add("StaticTxt", SAPbouiCOM.BoFormItemTypes.it_STATIC)

        oItem.Left = 10

        oItem.Top = 10

        oItem.LinkTo = "EditTxt"

        oStatic = oItem.Specific

        oStatic.Caption = "Emp Code"

        ' Name

        oItem = oForm0.Items.Add("lblName", SAPbouiCOM.BoFormItemTypes.it_STATIC)

        oItem.Left = 10

        oItem.Top = 40

        oItem.AffectsFormMode = False

        oLabel = oItem.Specific

        oLabel.Caption = "Emp Name"

        oItem = oForm0.Items.Add("txtName", SAPbouiCOM.BoFormItemTypes.it_EDIT)

        oItem.Left = 100

        oItem.Top = 40

        oItem.AffectsFormMode = False

        oItem.Visible = True

        oItem.Enabled = True

        oItem = oForm0.Items.Add("btnAdd", SAPbouiCOM.BoFormItemTypes.it_BUTTON)

        oItem.Left = 10

        oItem.Top = 130

        oItem.AffectsFormMode = False

        oButton = oItem.Specific

        oButton.Caption = "Add"

        oEdit.DataBind.SetBound(True, "", "EditDS")

        oEdit.ChooseFromListUID = "CFL1"

    End Sub

Private Sub AddChooseFromList()

        Try

            Dim oCFLs As SAPbouiCOM.ChooseFromListCollection

            Dim oCons As SAPbouiCOM.Conditions

            Dim oCon As SAPbouiCOM.Condition

            oCFLs = oForm0.ChooseFromLists

            Dim oCFL As SAPbouiCOM.ChooseFromList

            Dim oCFLCreationParams As SAPbouiCOM.ChooseFromListCreationParams

            oCFLCreationParams = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams)

            oCFLCreationParams.MultiSelection = False

            oCFLCreationParams.ObjectType = "171"

            oCFLCreationParams.UniqueID = "CFL1"

            oCFL = oCFLs.Add(oCFLCreationParams)

        Catch

            MsgBox(Err.Description)

        End Try

    End Sub


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


If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then

                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent

                    oCFLEvento = pVal

                    Dim sCFL_ID As String

                    sCFL_ID = oCFLEvento.ChooseFromListUID

                    Dim oForm As SAPbouiCOM.Form

                    oForm = SBO_Application.Forms.Item(FormUID)

                    Dim oCFL As SAPbouiCOM.ChooseFromList

                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)

                    If oCFLEvento.BeforeAction = False Then

                        Dim oDataTable As SAPbouiCOM.DataTable

                        oDataTable = oCFLEvento.SelectedObjects

                        Dim val As String

                        Try

                            val = oDataTable.GetValue(1, 0)

                        Catch ex As Exception

                        End Try

                        If (pVal.ItemUID = "EditTxt") Then

                            oForm.DataSources.UserDataSources.Item("EditDS").ValueEx = val

                        End If

                    End If

                End If

end sub

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Dec 26, 2014 at 04:08 PM

    Hi Sunny,

    val = oDataTable.GetValue(1, 0)  or you can use it as follows:



    val = oDataTable.GetValue("firstName", 0)   //This line gives you the first name of the employee in val variable.


    EmpID = oDataTable.GetValue("empID", 0)   //This line gives you the Employee Id of the employee in val variable.



    Now you have to set these value in the EditText.



    Hope it helps.




    Thanks & Regards


    Ankit Chauhan


    Add comment
    10|10000 characters needed characters exceeded

    • Hi Sunny,

      For now, I can only say that you need to refer the correct FormID, ItemUID i.e. your EditText and also the correct event.

      "Object reference not set to an instance of the object" Error clearly states that you are using an object that is not initialized correctly.




      Hope it helps.




      Thanks & Regards


      Ankit Chauhan

  • avatar image
    Former Member
    Dec 26, 2014 at 04:25 PM

    Hi Sunny,

         Just use this code:

    After ChooseFromList:

    var lempID = Convert.ToString(aEvent.SelectedObjects.GetValue("empID", 0));
    var lfirstName = Convert.ToString(aEvent.SelectedObjects.GetValue("firstName", 0));
    
    

    I'm considering you want to select data from the

    I suggest to add the code in After Validate the component, to clear the values when the value of the code is blank.

    Regards,
    Paulo Henrique

    Add comment
    10|10000 characters needed characters exceeded