B4J Question Fill Comboxes from SQLFile, dependent on Filter, set from the Comboboxes

mw71

Active Member
Licensed User
Hello,

I have a set of combo boxes (e.g. date....). The filling of these is done from a SQL file.
If now the selection of a combo box is changed (e.g. a date is selected)
- a filter should be generated (no problem)
- all ComboBoxes should be filled again (with a new query from the SQL file with the generated filter)
-> the contents of the combo boxes should be dependent on each other like this

Unfortunately the ChangeEvents is called again and again, so it goes around in circles.

This Sub Fill the Combobox and its call by the ChangedEvent (at the moment, thats the Problem i think)
B4X:
Sub fill_Spinner_Filter(SQL As SQL, SpinnerX As ComboBox, Feld As String, Filter As String, UpCase As Boolean)

    Dim selItem As String
    Dim query_Spinner As StringBuilder
    Dim Spinner_Multi As Boolean = False

    If SpinnerX.Items.Size>0 And SpinnerX.SelectedIndex>=0 Then
        Dim SpinnerX_Item As String = SpinnerX.Items.Get(SpinnerX.SelectedIndex)
        selItem = SpinnerX_Item 'derzeit ausgewähltes Item, damit es danach wieder so gesetzt werden kann
        If SpinnerX_Item.Contains("%") Or SpinnerX_Item.Contains("*") _
              Or SpinnerX_Item=varTxtLeer Or SpinnerX_Item=varTxtnichtLeer Then Spinner_Multi=True
    End If

    query_Spinner.Initialize

    gen_Filter(0)    'Generate the Filter'
    
    If UpCase = True Then
        query_Spinner.Append("SELECT DISTINCT UPPER(" & Feld & ") FROM log")
    Else
        query_Spinner.Append("SELECT DISTINCT " & Feld & " FROM log")
    End If
    
    If starter.varFilter <>"" Then query_Spinner.Append(" WHERE " & starter.varFilter & " COLLATE NOCASE")  'COLLATE NOCASE -> Case InSensitive
    query_Spinner.Append(" ORDER By UPPER(" & Feld & ") asc")
    Log("fill_Spinner query: " & query_Spinner.ToString)

    SpinnerX.items.Clear
    SpinnerX.items.Add ("")          'add for ampty Line



    Dim cur As ResultSet = SQL.ExecQuery(query_Spinner.ToString)

    Do While cur.NextRow
        Dim Value As String = cur.GetString2(0)
        If Value<>"" And Value<>" " Then
            If Value.length=8 And Feld = "Datum" Then
                SpinnerX.items.Add(ServiceModul.DatumFormatieren(cur.GetString2(0)))
            Else
                SpinnerX.items.Add(cur.GetString2(0))
            End If
        End If
    Loop
    cur.close

    Try
        SpinnerX.SelectedIndex=SpinnerX.items.indexof(selItem)
    Catch
        Log(LastException)
    End Try
End Sub
 

LucaMs

Expert
Licensed User
You need a module level Boolean variable to check if the change event is triggered by the user (click on combo) or by your code.
If by your code, exit immediately from the event routine.
 
Upvote 0

mw71

Active Member
Licensed User
hi,

thanks for your anser LucaMs,
i use B4XPages and have in the Class_Globals declare a Boolean Variable.

With the first ChangeEvent i set the Variable to True and after i have update all to False.
If a ChangeEvent is rised, i first check if the Variable is False. Start the Update only if it False.

Unfortunately it not work as exeptet.


I hope that I can create a test project (that will certainly not before 20:00 UTC)
 
Upvote 0
Top