cancel
Showing results for 
Search instead for 
Did you mean: 

ComboBox with Define New

Former Member
0 Kudos

Hi,

Is it possible to create a ComboBox with the possibility to Define new values?

I tried to create a user-defined table with the values, but I don't know how to link this table to the ValidValues of the ComboBox I created.

Thank you again for your help

Thibault

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Thibault,

I have also thought about this previously. You can add a standard combo box to your window, but you will have to populate the values manually. Like this:

oRecord = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
oRecord.DoQuery("SELECT Code, Name FROM [@XXXX]")
oRecord.MoveFirst()
While Not oRecord.EoF
     oCombo.ValidValues.Add(oRecord.Fields.Item("Code").Value, oRecord.Fields.Item("Name").Value)
     oRecord.MoveNext()
End While

What you'll have to do then is add another entry that says define new. So your code will be:

oCombo.ValidValues.Add(" ", "Define New")

Then you'll have to check whether the last entry was selected and then show the UDF form. This you can do with this code:

        Dim oMenu As SAPbouiCOM.MenuItem
        Dim sVal As String
        Dim sMenuUID As String
        Dim s As String
        Dim i As Integer
        sVal = "MYTABLE"
        Try
            oMenu = oApplication.Menus.Item("51200")
            For i = 0 To oMenu.SubMenus.Count - 1
                If oMenu.SubMenus.Item(i).String.Length < sVal.Length Then
                    s = oMenu.SubMenus.Item(i).String
                Else
                    s = oMenu.SubMenus.Item(i).String.Substring(0, sVal.Length)
                    If s.Compare(s, sVal, True) = 0 Then
                        sMenuUID = oMenu.SubMenus.Item(i).UID
                    End If
                End If
            Next
            oApplication.ActivateMenuItem(sMenuUID)
        Catch ex As Exception
            oApplication.MessageBox(ex.Message)
        End Try

I haven't tried this whole thing in total like this, but in theory it should work.

Hope it helps,

Adele

Former Member
0 Kudos

Hi Adele,

Thanks for your helpful answer!

However, I can't create a Recordset in my program... the compiler tells me "Object reference not set to an instance of an object".

I tried to write Dim oRecord As New Recordset, but it didn't work either.

What is the solution?

Thanks

Thibault

Former Member
0 Kudos

Hi Thibault,

You define it as:

Dim oRecord As SAPbobsCOM.Recordset
oRecord = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

Hope it helps,

Adele

Former Member
0 Kudos

Hi again,

Yes, I tried also like this, and same error...

Thibault

Former Member
0 Kudos

Hi Thibault,

Are you connected to a company? Check this with something like

oApplication.Messagebox(oCompany.CompanyName)

Hope it helps,

Adele

Former Member
0 Kudos

Hi,

Before you create instance for oRecordset, you must create a object for oCompany and you should connect to company database. I think following code snipet will be help for you

Private WithEvents SBO_Application As SAPbouiCOM.Application

Dim oCompany As SAPbobsCOM.Company

Dim oGUI As New SAPbouiCOM.SboGuiApi

Dim sCookie As String

Dim sCookieContext As String

Dim iError As Integer

Try

oGUI.Connect(Environment.GetCommandLineArgs.GetValue(1))'SDK Sample will help you to understand this line

SBO_Application = oGUI.GetApplication

oCompany = New SAPbobsCOM.Company

sCookie = oCompany.GetContextCookie

sCookieContext = SBO_Application.Company.GetConnectionContext(sCookie)

oCompany.SetSboLoginContext(sCookieContext)

If oCompany.Connect() <> 0 Then

Status = "Error While Connection To Company Database!"

Exit Sub

Else

Status = "Connection Established To Company !"

End If

Catch

Status = Err.Description

End Try

I hope this will be hlep for you

With Regards

B Ravi Shankar

Former Member
0 Kudos

Hi Adele,

Yes, I wasn't connected to the company... I'm beginning with SDK and this didn't cross my mind.

Thank you very much, my problem is solved !

Regards,

Thibault

Former Member
0 Kudos

Hi Ravi,

Thank you for your code too !

It is very helpfull.

Regards,

Thibault

Answers (0)