cancel
Showing results for 
Search instead for 
Did you mean: 

populate Matrix combo-column from Db

Former Member
0 Kudos

Hi all, this is my first Thread!

I'm a VB.NET developer. The question is:

How I can populate programmatically a Matrix combo-column?

I have found this method:

oForm.DataSources.DataTables.Add("DATA").ExecuteQuery("SELECT * FROM [ACR4]")
oMatrix.Columns.Item("col1").DataBind.Bind("DATA", "CardCode")
oMatrix.LoadFromDataSource()

but this code add a row in matrix for each record.

Regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Luke,

I call this code in the MatrixAddRow() function.

Bye

P.S. Look for [ClearCombo(oCombo)|; function.


Private Sub InitComboBox(ByRef oForm As SAPbouiCOM.Form)
    Try
        If SBO_Company.Connect Then
            oForm.Freeze(True)
            '
            ' Matrix
            Dim oMatrix As SAPbouiCOM.Matrix
            oMatrix = oForm.Items.Item(MatrixID).Specific
            If oMatrix Is Nothing Then Throw New Exception("Error: matrix object a nothing")
            '
            ' Matrix column
            Dim oColumn As SAPbouiCOM.Column
            oColumn = oMatrix.Columns.Item(sMatrixComboColumnName)
            '
            ' Matrix column cell
            Dim oCell As SAPbouiCOM.Cell
            oCell = oColumn.Cells.Item(oMatrix.VisualRowCount)
            '
            ' Matrix column cell combo
            Dim oCombo As SAPbouiCOM.ComboBox
            oCombo = oCell.Specific

            If ClearCombo(oCombo) Then
                Try
                    ' First value, if the field is not required
                    oCombo.ValidValues.Add("", "")

                    Dim oRS As SAPbobsCOM.Recordset
                    oRS = SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                    Dim sSql As String = "SELECT Code, Name FROM [@YOUR_TABLE_FOR_COMBO_VALUES] ORDER BY 1"
                    oRS.DoQuery(sSql)
                    oRS.MoveFirst()
                    While oRS.EoF = False
                        oCombo.ValidValues.Add(oRS.Fields.Item("Code").Value, oRS.Fields.Item("Name").Value)
                        oRS.MoveNext()
                    End While

                    ' Last value, if you want/need to define new...to have some SAP like...TODO
                    oCombo.ValidValues.Add("Define", "Define")

                    If Not oRS Is Nothing Then
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oRS)
                        oRS = Nothing
                    End If
                Catch ex As Exception
                    ' log exception
                Finally
                    oCombo = Nothing
                    oCell = Nothing
                    oColumn = Nothing
                    oMatrix = Nothing
                End Try
            End If
        End If
    Catch ex As Exception
        ' log exception
    Finally
        oForm.Freeze(False)
        System.GC.Collect() 'Release the handle to the table 
    End Try

End Sub

Former Member
0 Kudos

Ok, now the problem in another. To use RecordSet I have to Connect to a Company with:

Dim SboGuiApi As SAPbouiCOM.SboGuiApi
            Dim sConnectionString As String

            SboGuiApi = New SAPbouiCOM.SboGuiApi

            sConnectionString = Environment.GetCommandLineArgs.GetValue(1)

            '// connect to a running SBO Application

            SboGuiApi.Connect(sConnectionString)

            '// get an initialized application object

            App = SboGuiApi.GetApplication()

 If Soc Is Nothing Then
                Soc = New SAPbobsCOM.Company

                Dim ConStr As String
                Dim Ret As Long

                ConStr = App.Company.GetConnectionContext(Soc.GetContextCookie)

                Ret = Soc.SetSboLoginContext(ConStr)

                If Not Ret = 0 Then
                    App.MessageBox("Error.")
                    Exit Function
                End If
                _Ret = Soc.Connect()_

                Conn = Ret = 0
            Else
                Conn = Soc.Connected
            End If

But on underlined line of my code the application is taking too much time to connect, so I was finding another code for populate my combo...

Have you any idea to solve this problem?

Bye

Former Member
0 Kudos

Hi Luke.

This is only the sequence of call, but for all functions you can look in SAP SDK Examples.

On all time of life of your window you have

 If SBO_Company.Connect Then... 'do something what need Recordset object... 

Bye



' company
Private SBO_Company As SAPbobsCOM.Company

Public Sub New()

  Call SetApplication() ' You example is good...
  Call SetConnectionContext() ' Here you initialize your SBO_Company...
  Call ConnectToCompany() ' for connection if it Not Connected ...

  ' finally
  Call ...()

End Sub

Edited by: Sierdna S on Jun 6, 2008 1:32 PM

Former Member
0 Kudos

>

> On all time of life of your window you have

>

 If SBO_Company.Connect Then... 'do something what need Recordset object... 

Yes, of course! I call SBO_Company.Connect in Public Sub New() and this take a lot of time for start Add-on.

Regards

Answers (1)

Answers (1)

former_member682029
Contributor
0 Kudos

Set the Type property of the column object to it_COMBO_BOX.

also add Valid values to the Column object.

Anoop

Former Member
0 Kudos

I have my column type set to it_COMBO_BOX and if I try to populate the combo with:

oCmb2 = oMatrix.Columns.Item("col1").Cells.Item(oMatrix.RowCount).Specific
                oCmb2.ValidValues.Add("Test1", "Test")
                oCmb2.ValidValues.Add("Test2", "Test")
                oCmb2.ValidValues.Add("Test3", "Test")

it works as you can see here [Image|http://img58.imageshack.us/my.php?image=immaginewt8.jpg]

Thanks for reply.

Former Member
0 Kudos

Thats ok, the combo shows both values.

Former Member
0 Kudos

Ok, but I want populate my combo with Db records(dinamically)...

Nussi
Active Contributor
0 Kudos

than use a recordset and fill the combobox within a loop

regards

David

Former Member
0 Kudos

If I use RecordSet I must to be connected to a company and this take a lot of time, when I use this code:

...
Soc.Connect()
...

it takes about 1 minute to connect to company. So I through to use the method described in my first post.

Regards