How do I set the value (text) in a web PopUpMenu? What I do is load data from a database into a form… the Popupmenu should show the value that is stored in the database and the user can then change the value by selecting a different row / value from the popupmenu.
This was working in Xojo 2019.r3 but with the changes the code / properties instituted since then my code no longer does this function.
That does let me READ the value of the popupmenu… how do i SET the value of the popupmenu? I used to just popupmenu.text = some-text but that no longer works
PopupMenu1.AddRow( "Your Value" )
// Now 'Select' that value
PopupMenu1.SelectedRowIndex = PopupMenu1.LastAddedRowIndex
Maybe I don’t understand what you are trying to do.
- new Xojo Web
- add Popup
- code in open event:
for i as integer = 1 to 10
me.text = "4"
- Opening event same code as above
- Shown event:
Can you explain a little different or post some code on what you are doing and what you want to do?
I have a form that loads client data… one of the data points is contained in a set of choices in a popupmenu on the page. The client can change that data to one of the other choices, but when the information is loaded I want that popumenu control to show the data that was previously saved and was just retrieved from the database.
What you need has been explained by @AlbertoD in the post above
Something like this?
var rs as RowSet
//db is the database
rs=session.db.SelectSQL("SELECT ColumnName from TableName WHERE Your Criteria Here")
if rs<>nil then
while not rs.AfterLastRow
Catch error as DatabaseException
MessageBox ("Error: " + error.Message)
WebListbox Web 2.0 has:
SelectedRowValue Returns the value of the currently selected row.
SelectRowWithValue Selects the row with the provided value.
Maybe you read my post as #1 instead of #2.
#1 read the value of the popupmenu
#2 set the value of the popupmenu using the value that you provide, for example: value retrieved from the database
Yes, I think I did mis-read your original response. Thank you.
Thank you Eric… that works. Alberto’s suggestion worked for 2019, but not for 2021.
I don’t understand. Eric’s code doesn’t actually set the value. Alberto’s does.
Unless I misunderstood the question in the initial post it should do what he asked.
He wants to populate a WebPopupMenu from the values in a database column, right? That’s what that code does.
I answered this question:
Sorry, I didn’t understand that the problem was adding rows from the database.
popupmenu.text = some-text