Set value for WebPopupMenu

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.

Maybe this will help:
https://documentation.xojo.com/api/user_interface/web/webpopupmenu.html#webpopupmenu-selectrowwithvalue

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.

Xojo2019r3.2:

  • new Xojo Web
  • add Popup
  • code in open event:
for i as integer = 1 to 10
   me.addrow(i.tostring)
next
  • code in shown event:
me.text = "4"
  • result:

image

Xojo 2021r2.1:

  • Opening event same code as above
  • Shown event:
me.SelectRowWithValue("4")
  • result:

image

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 :wink:

1 Like

Something like this?

var rs as RowSet
//db is the database
try
  rs=session.db.SelectSQL("SELECT ColumnName from TableName WHERE Your Criteria Here")
  if rs<>nil then
    YourPopupMenu.RemoveAllRows
    while not rs.AfterLastRow
      self.YourPopupMenu.AddRow rs.Column("ColumnName").value
      rs.MoveToNextRow
    wend
    
  end if
Catch error as DatabaseException
  MessageBox ("Error: " + error.Message)
end try

Gary,

WebListbox Web 2.0 has:

  1. SelectedRowValue Returns the value of the currently selected row.
  2. 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.

Before (2019):
popupmenu.text = some-text

Now (2021):
popupmenu.SelectRowWithValue(some-text)