cancel
Showing results for 
Search instead for 
Did you mean: 

Get the selected item from a combo box

leon_laikan
Participant
0 Kudos

Hi, everybody

I have created a grid in a folder.

One column of the grid is called TransferTo. I made this column into a column of combo boxes.

The combo box works well, but when I select an item, it does not go into the TransferTo field on the grid.

Please help me write the correct code.

How to bind?

Thanks

Leon Lai

--------------------

My relevant code is as below:

        '==============================================

        '//INSERT CHECKBOX IN COLUMN

        '==============================================

        oGrid.Columns.Item("TransferTo").Type = SAPbouiCOM.BoGridColumnType.gct_ComboBox

        Dim oCombo As SAPbouiCOM.ComboBoxColumn

        oCombo = oGrid.Columns.Item("TransferTo")

        Dim oRecordSet As SAPbobsCOM.Recordset

        Dim StrQuery As String

        oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

        StrQuery = "Select T0.CardCode,T0.CardName FROM OCRD T0 ORDER BY T0.CardCode  "

        oRecordSet.DoQuery(StrQuery)

        oRecordSet.MoveFirst()

        While Not oRecordSet.EoF

            oCombo.ValidValues.Add(oRecordSet.Fields.Item("CardCode").Value.ToString, oRecordSet.Fields.Item("CardName").Value.ToString)

            oRecordSet.MoveNext()

        End While

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

Use the DataTable property on your grid to set the value.

oGrid.DataTable.SetValue("columnId", row, value);


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leon_laikan
Participant
0 Kudos

Hi Pedro,

I tried your formula like this:

oGrid.DataTable.SetValue("TransferTo", row, value)

But, when I build, it says:

row is not declared

value is not declared.

Thanks

Leon Lai

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

Yes, those you have to pass in. I just put in the names of the parameters of the function.

You must replace the row with the row that you want to fill in (if using an event you can get it from pVal.Row) and the value with the value you wish to set the field to (one of the valid values you just added).


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leon_laikan
Participant
0 Kudos

Hi Pedro,

I amended my code as foll:

If FormUID = "Pc2Fc"

     And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_COMBO_SELECT)

     And (pVal.BeforeAction = True) Then

    

            oGrid.Columns.Item("TransferTo").Type =                SAPbouiCOM.BoGridColumnType.gct_ComboBox


            Dim oCombo As SAPbouiCOM.ComboBoxColumn

            oCombo = oGrid.Columns.Item("TransferTo")

            oGrid.DataTable.SetValue("TransferTo", pVal.Row, oCombo.ValidValues("CardCode"))

End If

At runtime, it gave the foll. error msg:

Conversion from string "CardCode" to type 'Integer' is not valid.

What code should I put for value ?

Thanks

Leon Lai

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

I've just noticed that you are trying to put the value of the combobox in the grid where the combobox is (I though initially that you wanted to extract the value to place it somewhere else in the grid).

When you select the value from a combobox it's automatically added to the underlying field. You don't need to set it yourself.

How are you populating the grid? With a query or looping through rows?


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leon_laikan
Participant
0 Kudos

Hi,Pedro

My grid is populated from a query:

'==============================================

'//Set the grid data

'==============================================

        oForm.DataSources.DataTables.Add("MyDataTable")

        oForm.DataSources.DataTables.Item(0).ExecuteQuery _

          ("Select           T0.DocEntry,T0.DocNum,T0.DocStatus,T0.CANCELED,

                                   T0.CardCode,T0.CardName,'IN'   AS[Type],                                                          T0.DocDate,T0.DocTotal,T0.DocTotalFc, ' ' AS [TransferTo],

                                   ' ' AS [Done],' ' AS [Recon]          


          FROM OINV T0  WHERE T0.DocStatus ='O' And T0.CANCELED ='N'

oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")

oForm.State = SAPbouiCOM.BoFormStateEnum.fs_Maximized

Thanks,

Leon Lai

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

When you populate a grid from a query the column character size is taken from the largest value.

Since you have '' as [TransferTo] your length for that column will be 1 I believe.

Try changing to CAST('' AS NVARCHAR(254)) this will get you 254 characters length and the combobox should start working.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leon_laikan
Participant
0 Kudos

Hi Pedro,

It's wonderful!

Your suggestion works perfectly.

Best Regards,

Leon Lai

Answers (1)

Answers (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

Ps: The code you showed will only populate the "available values" of the combobox.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn