cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in Combo Select

Former Member
0 Kudos

Hi,

In my form i have a combo. My requirement is, for example i load 5 data A,B,C,D,E in combo. First i select the 'A' and load the corresponding elements in the matrix, next i select 'B' and the corresponding elements of 'B' was loaded in matrix now again i select 'A ' it should check 'A' is already selected and the corresponding elements are already displayed in matrix again the elements of 'A' should not be loaded in matrix. Plz tell how to check this.

Thanks in Advance.

Regards,

Madhavi

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

U can put this code into itemevent for button's et_ITEM_PRESSED with beforeaction = true :

Set objComboBox = objForm.Items.Item("combo").Specific

Set objMatrix = objForm.Items.Item("mtx").Specific

Set objColumns = objMatrix.Columns

For loopcombo = 0 to (objcombobox.ValidValues.Count - 1)

strComboValue = Trim(objComboBox.ValidValues.Item(loopcombo).Value)

blnExist = False

For i = 1 To objMatrix.RowCount

If trim(objColumns.item("newcolumn").Cells(i).Specific.Value) = strComboValue Then

blnExist = True

exit for

End If

Next i

if Not blnExist then

bubbleevent = false

---display some message error here

exit sub

End If

Next loopcombo

Former Member
0 Kudos

Hi Riny,

Thanks its working well.

Regards,

Madhavi

Former Member
0 Kudos

Yes, the code assume the combobox not inside the matrix.

Which part or code that confuse u ?

Former Member
0 Kudos

Hi Riny,

If combo has A,B,C,D all this A,B,C,D should be loaded in the matrix before we click the add button. If A,B is added and C,D is left while adding it should give the msg should select all the items in the combo. How can we validate it.

Former Member
0 Kudos

Hi Riny,

Thanks its working well. Here i want solution for another problem. All the items loaded in the combo should be selected before we press the add button can we do this.

Madhavi

Former Member
0 Kudos

U can put this code into itemevent for et_combo_select :

Set objComboBox = objForm.Items.Item("combo").Specific

strComboValue = Trim(objComboBox.Selected.Description)

Set objMatrix = objForm.Items.Item("mtx").Specific

Set objColumns = objMatrix.Columns

blnAdd = True

For i = 1 To objMatrix.RowCount

If trim(objColumns.item("newcolumn").Cells(i).Specific.Value) = strComboValue Then

blnAdd = False

bubbleevent = false

exit sub

End If

Next i

If blnAdd then

---U can put code here to run select query, and the query result is adding to the matrix.

---When add into the matrix, fill also objColumns.item("newcolumn").Cells(i).Specific.Value = strComboValue

End If

Former Member
0 Kudos

hi riny,

The combo selected is not in the matrix it is in the header. when we choose the item in the header the corresponding elements load in the matrix. for this how should i check.

Madhavi

Former Member
0 Kudos

Hi Madhavi,

here are the main parts of my little example.

Some hints:

The form is managed in a shared class (only one form at a time)

The Matrix is loaded via a DataTable

The Matrix is ReLoaded on every time the "ABCDE-Combo" is selected (except the value is already selected)

In the example I load Businesspartners into matrix where their CardName starts with A or B or....or E (you must adapt it for your needs)

SboCon.SboDI is the SAPbobsCOM.Company

SboCon.SboUI is the SAPbouiCOM.Application

Some global vars (initialize them somewhere when the form is opened!):


    Private Shared oForm As SAPbouiCOM.Form
    Private Shared oUds As SAPbouiCOM.UserDataSources
    Private Shared oDts As SAPbouiCOM.DataTables
    Private Shared oDtBp As SAPbouiCOM.DataTable
    Private Shared oMtxBp As SAPbouiCOM.Matrix

    Private Shared SelVals As System.Collections.ArrayList ' The values of the combo which already selected by the user

Init the vars somewhere (where you normally do this) on form load:


            oForm = '...set it in your way
            oDts = oForm.DataSources.DataTables
            oUds = oForm.DataSources.UserDataSources
            oMtxBp = oForm.Items.Item("MTX_BP").Specific

           ' DataBinding and related:

            '### Data Tables
            '#
            oDts.Add("DT_BP")
            '#
            '###

            '### UserDataSources
            '#
            '# ABCDE Combo:
            oUds.Add("UDS_SELBP", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 100)
            oForm.Items.Item("CBX_SELBP").Specific.databind.setbound(True, "", "UDS_SELBP")
            '#
            '###

            '### Fill ABCDE Combo 
            '#
            oForm.Items.Item("CBX_SELBP").DisplayDesc = True
            oCbx = oForm.Items.Item("CBX_SELBP").Specific
            oCbx.ValidValues.Add("0", "Please select...")
            For val As Integer = Asc("A") To Asc("E")
                oCbx.ValidValues.Add(Chr(val), "Load " & Chr(val) & " BP")
            Next
            oUds.Item("UDS_SELBP").ValueEx = "0"
            '#
            '###

The Combo Select Event:



            If pVal.ItemUID = "CBX_SELBP" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_COMBO_SELECT Then
                If Not pVal.BeforeAction Then
                    If oUds.Item("UDS_SELBP").ValueEx != "0" Then
                        Dim oCbx As SAPbouiCOM.ComboBox = oForm.Items.Item("CBX_SELBP").Specific

                        If SelVals.Contains(oUds.Item("UDS_SELBP").ValueEx) Then
                            ' BP already selected - do nothing
                            SboCon.SboUI.StatusBar.SetText("Already selected!")
                        Else
                            If Not SelVals.Contains(oUds.Item("UDS_SELBP").ValueEx) Then
                                SelVals.Add(oUds.Item("UDS_SELBP").ValueEx)
                            End If
                            Dim query As String

                            oDtBp.Clear()
                            oMtxBp.Clear()

                            ' Build query for BPs where their names starts with the Combo-Value
                            query = "SELECT CardCode, CardName FROM OCRD WHERE "
                            For i As Int16 = 0 To SelVals.Count - 1
                                If i > 0 Then query &= " OR "
                                query &= "CardName LIKE '" & SelVals(i) & "%' "
                            Next
                            query &= " ORDER BY CardName"

                            ' load the MTX via DataTable (reloaded every time based on collected combo-values)
                            oDtBp.ExecuteQuery(query)
                            With oMtxBp.Columns
                                ' Zeilen-Nr.
                                .Item("0").DataBind.Bind("DT_BP", "CardCode")
                                ' 
                                .Item("1").DataBind.Bind("DT_BP", "CardName")
                            End With
                            oMtxBp.LoadFromDataSource()

                            oMtxBp.AutoResizeColumns()

                            SboCon.SboUI.StatusBar.SetText(oUds.Item("UDS_SELBP").ValueEx & " added!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
                        End If

                        ' reset Combo to "Please select..."
                        oUds.Item("UDS_SELBP").ValueEx = 0
                    End If
                End If
            End If

ATTENTION: REPLACE the "!=" with less (<)/greater(>) symbol, they're not shown in ths forum

I hope I didn't forget sth. - here it works..

Cheers,

Roland

Edited by: Roland Toschek on Sep 25, 2008 11:54 AM

Former Member
0 Kudos

Hi

Try this with little modifications: change combobox name "cComboABC"; write Matrix_Fill(...) function.

Hope to help

Regards

Sierdna S.


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 = "cComboABC" _
  And pVal.BeforeAction = False _
  And pVal.ItemChanged = True _
  Then
    Try

        Dim oCombo As SAPbouiCOM.ComboBox
        Dim sValue As String = ""
        oCombo = oForm.Items.Item("cComboABC").Specific()
        If oCombo.Selected Is Nothing Then Throw New Exception("Select some value...")
          sValue = oCombo.Selected.Value
          ' ++++++++++++++++++++++++++++++++++++
          Select Case 
            Case "A"
              ' fill matrix for "A"
              Call Matrix_Fill(oForm,"A")
            Case "B"
              ' fill matrix for "B"
              Call Matrix_Fill(oForm,"B")
            Case "C"
              ' fill matrix for "C"
              Call Matrix_Fill(oForm,"C")
            Case "..."
              ' fill matrix for "..."
              Call Matrix_Fill(oForm,"...")
            Case else
          End Select 
          ' ++++++++++++++++++++++++++++++++++++
        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

Private Sub Matrix_Fill(ByRef oForm As SAPbouicom.Form, sWitch As String)
  Dim sSql As String = ""
  sSql = "SELECT DocNum,.. FROM ... WHERE ..." ' modify select
  oRS = SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
  oRS.DoQuery(sSql)
  If oRS.RecordCount > 0 Then
    Dim i As Integer = 0
    oRS.MoveFirst()
    While oRS.EoF = False
      i = i + 1
      ' add matrix columns
      oForm.DataSources.UserDataSources.Item("uNr").Value = i     ' 1" matrix column for row number
      oForm.DataSources.UserDataSources.Item("uDocNum").Value = oRS.Fields.Item("DocNum").Value
      '... 
      oMatrix.AddRow()
      oRS.MoveNext()
   
    End While
 
  End If

End Sub

Edited by: Sierdna S on Sep 25, 2008 9:21 AM

Former Member
0 Kudos

How about this :

Add one column which its value come from the combobox. And when u select the combobox, u loop the matrix and check the column's value whether there is row from the selected value from the combobox or not.

Regards,

Riny

Former Member
0 Kudos

Hi Riny,

I already tried as u said but i dont know how to check the value in matrix already exist. The code follow plz help how to do

Dim i As Integer

Dim CatVal As String

Dim rs As SAPbobsCOM.Recordset

Try

rs = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

rs.DoQuery("select distinct(U_catcode),U_paramcat from [@PSSIT_NPLANHDR] a, [@PSSIT_NPLANDTL] b where a.code = b.code and U_catcode is not null and a.u_itemcode ='" & itemcode & "' and a.U_supcode='" & supcode & "' ")

rs.MoveFirst()

For i = 1 To Oform.Items.Item("mat2").Specific.RowCount

CatVal = rs.Fields.Item(0).Value

If InStr(Oform.Items.Item("mat2").Specific.Columns.item("CatCode").Cells(i).Specific.Value, " & CatVal & ") > 0 Then

-


What Condition i should give here----


End If

Next i

Catch ex As Exception

Throw ex

End Try

madhavi

Edited by: Madhavi on Sep 25, 2008 9:55 AM

Former Member
0 Kudos

Hi,

U need to write ur code in the combo select event in the Before action = False part....

My suggestion is it will be more flexible for u if u have different matrices with differnt data and just make them visible and invisible depending on the value selected in the combo box.

Hope it helps,

Vasu Natari.