Good evening group, I have a PopUp menu, where I have assigned a list of names, and each name corresponds to an ID inserted in RowTag. When the list is closed, by clicking on a ListBox, I would like to reopen the PopUpMenu and recall the row corresponding to the chosen name, with the relative ID in RowTag.
'ListBoxEventi.CellTextAt(ListBoxEventi.SelectedRowIndex,1) 'MY NAME TO SEARCH
Var sql As String = "SELECT * FROM ColoriTipoMonitoraggioEventi WHERE Tipo='" +ListBoxEventi.CellTextAt(ListBoxEventi.SelectedRowIndex,1)+"'"
Var RecordFinder As RowSet = db.SelectSQL(sql)
Dim ID_Tipo as integer
'MY l'ID in a RowTagAt of PopUpMenu
While Not RecordFinder.AfterLastRow
PopupMenuSceltaTipologia.RowTagAt(PopupMenuSceltaTipologia.SelectedRowIndex)=RecordFinder.Column("ID").StringValue)
RecordFinder.MoveToNextRow
Wend
RecordFinder.Close
I would like to be able to have the selected value in the popUpMenu and make sure that when opening the popupmenu drop-down menu, this value remains selected, while still giving me the option to choose another one.
Var tipo As String = ListBoxEventi.CellTextAt(ListBoxEventi.SelectedRowIndex, 1)
Var sql As String = "SELECT * FROM ColoriTipoMonitoraggioEventi WHERE Tipo = ?"
Var recordFinder As RowSet = db.SelectSQL(sql, tipo)
While Not recordFinder.AfterLastRow
Var id As String = recordFinder.Column("ID").StringValue
Var tipoDB As String = recordFinder.Column("Tipo").StringValue
For i As Integer = 0 To PopupMenuSceltaTipologia.LastRowIndex
If PopupMenuSceltaTipologia.RowTagAt(i).StringValue = id Then
PopupMenuSceltaTipologia.SelectedRowIndex = i
Exit For
End If
Next
recordFinder.MoveToNextRow
Wend
recordFinder.Close
Eventi.ListBoxEventi.DoublePressed, line 22
Type “DesktopPopupMenu” has no member named “SelectRowWithText”
PopupMenuSceltaTipologia.SelectRowWithText(ListBoxEventi.CellTextAt(ListBoxEventi.SelectedRowIndex, 1))
If no row is selected “ListBoxEventi.SelectedRowIndex” will return -1, which will then trigger an exception. Try:
If ListBoxEventi.SelectedRowIndex <> -1 then
PopupMenuSceltaTipologia.SelectRowWithText( ListBoxEventi.CellTextAt( ListBoxEventi.SelectedRowIndex, 1 ) )
else
PopupMenuSceltaTipologia.SelectedRowIndex = -1 // Select nothing.
End if
yes, when I try to run the code, it tells me this: Eventi.ListBoxEventi.DoublePressed, line 23
Type “DesktopPopupMenu” has no member named “SelectRowWithText”
PopupMenuSceltaTipologia.SelectRowWithText( ListBoxEventi.CellTextAt( ListBoxEventi.SelectedRowIndex, 1 ) )
I use Xojo 2023 1.1
Ok, I don’t know… it always gives me problems. Maybe it doesn’t exist for my version? I would have liked to have a more concise and functional code, but at this point I leave mine that I know works.
Now that we established that your Xojo version does not have the method that will help you, can we discuss your code?
It is strange that you get the ‘tipo’ from the listbox SelectedRowIndex, then query the database for all the records that have the ‘tipo’ just to pull the ‘tipo’ from the record (should be the same as the listbox), then use the id to find the RowTag.
Questions:
does your database show several records with the same Tipo and different ID?
if so, how do you know which ID you want to use? Seems like your code can keep selecting different PopupMenuSceltaTipologia rows if the database has several records with same Tipo
if not, can’t you look for the Cell Text instead to match the Tipo without accessing the database?
Depending on your answers the code can be changed.
If you have only one record for Tipo, then maybe you can use this code:
Var tipo As String = ListBoxEventi.CellTextAt(ListBoxEventi.SelectedRowIndex, 1)
For i As Integer = 0 To PopupMenuSceltaTipologia.LastRowIndex
If PopupMenuSceltaTipologia.RowTextAt(i) = tipo Then
PopupMenuSceltaTipologia.SelectedRowIndex = i
Exit For
End If
Next
your code works better than mine, faster of course, I just had to replace .RowTextAt with RowValueAt.
the “EVENT” is only one type, called by ID. When I click on the row of the listbox, the same event remains selected on the combobox. That’s how it works. Thanks.
EVENT has been automatically translated into English, it is the name of my “EVENT” field, the one affected by the selection speech. For the rest OK, now everything works with an optimized code. Thanks.