Creating a popup menu through code.

Hello all,

So I am using xojo 16 r3, and am trying to create a new popup menu inside a function. As it is shown bellow:

Dim tempPM As New PopupMenu

For i As Integer = 0 To 10

tempPM.RowTag(tempPM.ListCount-1) = i


While the object gets created by the end of the iteration my popup is still empty, both rows and rowtags.
Do I need to have a popup menu window item in the window? Is it not possible to use the popup menu item simply in the code?

Thanks in advance!!

No. You can’t create a control from nothing.
Drag a pop up control onto your window. Set it outside the visible area if you like. Let’s say you name it “mypop”
Make it a control array. Now your code reads

Dim tempMP As New mypop

OP you need to display the menu before you can get a result:

Here’s a working example of how to use this in a PushButton.Action event:

Sub Action() Handles Action
  dim pmTemp as new MenuItem
  for i as Integer = 1 to 10
    pmTemp.Append(new MenuItem(str(i)))
  dim pmSelection as MenuItem = pmTemp.PopUp
  if pmSelection <> nil then
    MsgBox("Selected " + pmSelection.Text)
End Sub
1 Like

Thank you all for the replies, I ended up not using the popup menu. I used a Variant array to do the job I needed.

I works, so I am relieved! Thanx again!