Popup Menu Independent Caption

What’s the best way to implement an independent caption for a popup menu that is loaded from a database? For those popups that do not have a default value, I would like to have a caption that says, “Choose”, but I don’t want the user to be able to choose “Choose”.

Thank you

How about …
If hititem.Text = “Choose” then
// do nothing
else
me. Caption = Hititem.text
end if

i do something similar with combobox too… having a seperator in the list of item

Thanks guys, but I was looking for something more like the code below. However popupmenus don’t receive MouseUp unless you return true in MouseDown. See this post:
https://forum.xojo.com/12233-popupmenu-serious-bug/0

But I don’t want to use timers or declares, so I may just keep “Choose” in the list and forget about it.

Function MouseDown(X As Integer, Y As Integer) As Boolean
if me.Text = “Choose” then

me.blockChange = true
me.RemoveRow( 0 )
me.blockChange = false

end if
End Function

Function MouseUp(X As Integer, Y As Integer) As Boolean
if me.Text = “” then

me.blockChange = true
me.InsertRow 0, "Choose"
me.ListIndex = 0
me.blockChange = false

end if
End Function

On OS X, you could dig into the NSMenuItem and disable it, so it becomes unelectable. But it may look odd.

Alternatively capture the mousedown event and display a contextual menu without the “Choose” option. Use the system.mouseX - x and system.mouseY - y to make the menu appear as if it was a popup menu.

Set “Choose” as initial value in the Inspector

Function MouseDown(X As Integer, Y As Integer) As Boolean // Remove "Choose" so user cannot select it if me.list(0) = "Choose" then me.Removerow(0) end if End Function

[code]Sub Change()
// Do whatever you need to do with the selected row

// Redisplay “Choose”
if me.list(0) <> “Choose” then
me.listindex = 0
me.InsertRow(0,“Choose”)
end if
End Sub
[/code]

The PopupMenu caption will show “Choose”, but as soon as the user clicks, the option disappears. Then when an option has been selected, you do whatever you need to do, then after the end of Change, reinstate “Choose” as default value.

There is one situation when reinstating “Choose” cannot be done in Change, or any other event I found for that matter : when the user presses ESC. It cannot be trapped in Keydown and Close does not fire. The best way is probably to launch a single timer in MouseDown and reinstate Choose after a while.

This will have to be adapted as well for pure keyboard usage (mostly Windows), but that demonstrates the principle.

Thanks guys. I’ll be playing with these ideas.