on 03-05-2015 11:00 AM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.