Skip to Content
author's profile photo Former Member
Former Member

how to create define new?

i have taken combo box in form . i want to select define new option in combo box.

is it possible....?

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2008 at 11:46 AM

    Animesh,

    two options.

    1) give the last valid value as 'define new' and catch a combo select event for it and code to load the form where you want to define new option.

    2) better one is to link this combobox field to 'No object' type of table and in that table define all the values. 'Define New' option will be there by default as the last valid value in combo box.

    regards,

    Binita

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Animesh ,

      I don't have working code. but can outline it:

      1) Add a last valid value as 'define new' in combo box.

      2) catch a combo select event and check if 'Define New' is selected

      3) if yes, either load the user table form what you may have created with 'No Object' type or a user defined form where you can add a new value.

      ask if you still have doubts.

      regards,

      Binita

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2008 at 11:47 AM

    Hi..

    use this code

    Try

    ocombox = FormS.Items.Item("Combobox-ID").Specific

    RS = Nothing

    RS = OCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

    RS.DoQuery("Select Query")

    Try

    If RS.EoF = False Then

    For i = 1 To RS.RecordCount

    ocombo.ValidValues.Add(RS.Fields.Item("U_Shiftdef").Value, i)

    RS.MoveNext()

    Next

    'ocombo.ValidValues.Add("-9", "Define New")

    End If

    ocombo.ValidValues.Add("-9", "Define New")

    Catch ex As Exception

    SBO_Application.MessageBox(ex.Message)

    End Try

    Catch ex As Exception

    SBO_Application.MessageBox(ex.Message)

    End Try

    It will work...

    Regards...

    Billa 2007

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2008 at 12:42 PM

    Hi

    this is the method what I have used in the form with matrix what have the combobox column.

    Hope to help

    BR

    Sierdna S.

    CREATE FORM SUB

    Public Sub CreateForm(...)
    ...
      If oMatrix.RowCount > 0 Then
        Call InitializeMatrixCombo(oForm, _
                                   MatrixID, _
                                   "DSU_Linked", _  ' Combobox Column
                                   "@LINKED_TABLE", _
                                   "<Default_Value>" _
                                  )
      End If
    ...
    End Sub
    

    InitComboBox sub when we initializing combobox to combobox values we add also 2 new values:

    - "","" : NULL value, if database column accept null value

    - "Redefine","Redefine" : When selected with ItemEvent we activating menu with form uid where are we can define new values.

    Public Sub InitializeMatrixCombo( _
        ByRef oForm As SAPbouiCOM.Form, _
        ByVal sMatrixID As String, _
        ByVal sComboColumnName As String, _
        ByVal sLinkedTable As String, _
        Optional ByVal sDefaultValue As String = "" _
    )
      Try
        oForm.Freeze(True)
        If SBO_Company.Connect Then
          '
          ' Matrix
          Dim oMatrix As SAPbouiCOM.Matrix
          oMatrix = oForm.Items.Item(sMatrixID).Specific
          If oMatrix Is Nothing Then Throw New Exception("ERROR: matrix object is nothing"))
          '
          ' Matrix column
          Dim oColumn As SAPbouiCOM.Column
          oColumn = oMatrix.Columns.Item(sComboColumnName)
          '
          ' 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
              ' Add 1-st value if database field accept NULL
              oCombo.ValidValues.Add("", "")
    
              Dim oRS As SAPbobsCOM.Recordset
              oRS = SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
              Dim sSql As String = "SELECT Code, Name FROM [@" & sLinkedTable & "] 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
    
              ' Add DEFINE NEW value +++++++++++++++++++++++++++++++ 
              ' Note: Code can have length up to 8 caracters
              oCombo.ValidValues.Add("Redefine", "Redefine")
    
              If Not oRS Is Nothing Then
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oRS)
                oRS = Nothing
              End If
              System.GC.Collect() 'Release the handle to the table 
    
              ' Select dafault value if not null
              If Not sDefaultValue.Equals("") Then
                If oCombo.ValidValues.Count > 0 Then
                  oCombo.Select(sDefaultValue, SAPbouiCOM.BoSearchKey.psk_ByValue)
                End If
              Else
                If oCombo.ValidValues.Count >= 1 Then
                  oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
                End If
              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
    

    Item Event to handle selection of "Redefine" voice in combobox.

    Private Sub SBO_Application_ItemEvent( _
          ByVal FormUID As String, _
          ByRef pVal As SAPbouiCOM.ItemEvent, _
          ByRef BubbleEvent As Boolean _
    ) Handles SBO_Application.ItemEvent
    
      Dim oForm As SAPbouiCOM.Form
      oForm = SBO_Application.Forms.Item(FormUID)
    
      If pVal.EventType = SAPbouiCOM.BoEventTypes.et_COMBO_SELECT _
      And pVal.FormUID = sgloFormUID _
      And pVal.ItemUID = MatrixID _
      And pVal.ColUID = "DSU_Linked" _
      And pVal.BeforeAction = False _
      And pVal.ItemChanged = True _
      Then
        Try
          Dim oMatrix As SAPbouiCOM.Matrix
          oMatrix = oForm.Items.Item(MatrixID).Specific
          If oMatrix Is Nothing Then Throw New Exception("ERROR: matrix object is nothing")
          Try
            Dim oCombo As SAPbouiCOM.ComboBox
            Dim sValue As String = ""
            oCombo = oMatrix.Columns.Item("DSU_Linked").Cells.Item(pVal.Row).Specific
            sValue = oCombo.Selected.Value
            If sValue.Equals("Redefine") Then
              Try
                oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
                oForm.Refresh()
              Catch ex As Exception
               ' log exception
              End Try
              '
              ' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              ' Here place your menu uid to call the form for adding new value
              ' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              SBO_Application.Menus.Item("51207").Activate()
              '
            End If
            BubbleEvent = False
          Catch ex1 As Exception
            ' log exception
          End Try
        Catch ex As Exception
          ' log exception
        End Try
      End If
    
      ' Other events +++
    
    End Sub
    

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi

      1) It's not work because you need to verify InitializeCombo(...) function parameters.

      If, for example, your conmbobox item on form have uid="eCmb", when you need to call function so:

      Private Sub ShowAllItems(ByVal oForm)
        ...
        'Dim sCombo As String = "Define New"
        Dim sCombo As String = "eCmb"
        'Call InitializeMCombo(oForm, scombo, "@TEST_TABLE", "<Default_Value>")
        Call InitializeMCombo(oForm, sCombo, "@TEST_TABLE", "A")
      End Sub
      

      Function Parameters

      Public Sub InitializeMCombo( _
              ByRef oForm As SAPbouiCOM.Form, _  ' your form object
              ByVal sCombo As String, _                    ' ComboBox Item name
              ByVal sLinkedTable As String, _             ' Linked Table from where you need to load values
              Optional ByVal sDefaultValue As String = "" _  ' If do you want to load some default, existing in table, value.
      )
              Try
      ...
      

      2) Use an existing example from SDK Samples, for example 07.ComplexForm

      (find it in SDK_Samples_2005\COM UI\VB.NET\07.ComplexForm\2003).

      Add an item COMBO_BOX and add code to catch Item Event when you select the combobox value.

      Regards

      Sierdna S.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.