PopupMenu multiple choses

With Xcode it is possible to select multiple selections with the NSPopupButton
This doesn’t seem to be the case with PopupMenu in Xojo.

Do I miss something?

true north classical academy

What a timely question as I’ve been dealing with this myself this week. AFAIK this isn’t possible with the native Xojo PopupMenu as it only allows for a single selection.

Here’s the work around I’ve implemented in my own code, but be prepared for a bit of work in tracking, accounting for states, etc.

Here’s the key concept…

  1. Use the PopupMenu to bring up a ContextMenu instead of the native PopupMenu menu (which from what I can tell at least on Mac, is actually a context menu itself by the look and feel of things).
    1.1 Although I’m calling this a ContextMenu, technically it’s a DesktopMenuItem used in a contextual way.
  2. Use the PopupMenu to only display a single row so that something can be shown to the user as selected, not selected, or in the case of multiple values, a word of your choice such as “Multiple”.

Here are the logistics to pull this off via the various PopupMenu events…

  1. Opening
    1.1 Used to instantiate/setup the ContextMenu.
  2. MouseDown
    2.1 Used to present the ContextMenu and make sure to clone things.
    2.2 You’ll want to manage ContextMenu window placement here.
    2.3 You’ll need a variable that doesn’t go out of scope to store the selection such as selectedMenu as DesktopMenuItem within the window.
    2.4 Don’t forget to Return True for MouseUp.
  3. MouseUp
    3.1 Check the selectedMenu variable and if it’s nil then the user has clicked away without making a selection.
    3.2 Otherwise, handle the ContextMenu checkmarks, states, etc. within this code.
    3.3. Here’s a comment from my own code that’s useful to know, that maybe Xojo or someone else can shed some light onto…
    3.4. // Not sure how or why MouseUp happens after selecting the context menu, but it does
    3.5. // Would have expected the ContextualMenuItemSelected event to happen but it doesn’t
  4. SelectionChanged
    4.1 Address changes to PopupMenu (aka as proxy for the ContextMenu) here.
    4.2 I had to keep drilling into my head that the PopupMenu was just a single row and all my data lived in the ContextMenu.

Just the other day I tried to consolidate the logic of these items into generic methods as I have two popupmenus, but alas I couldn’t get it to work as something went haywire with the MouseUp event not getting called in time/in order. Maybe it was too late and my eyes were glazed over and I’ll just try again down the road.

So, although all of this is not an impossible task, plan on spending a bit of time in getting things working and customizing to your liking.

Hope this helps you or maybe someone else from the future.

1 Like

As a followup, I just created Feedback #72047 so that maybe one day Xojo can enhance the DesktopPopupMenu to support multiple selections.

1 Like

So it’s not working using this?

For i As Integer = 1 To 10
Var item As New DesktopMenuItem(i.toString)

If i = 4 Or i = 6 Or i = 9 Then
item.HasCheckMark = True
End If



I’d call this a bug then since DesktopMenuItems should be supported.

A workaround could be to use the :heavy_check_mark: Emoji to indicate selection and subclass it.

Why don’t you use the BevelButton class instead? It already handles showing a menu (including support for several checked items).
As for the fact it won’t show the selected item automatically, just show it as the caption (no need to hack the selected row).

This is exactly what I’m doing on my side to manage the selections via checkmark (e.g. implementing my own DesktopMenuItem instead of using the one built into the PopupMenu). Maybe I’m missing something with the DesktopPopupMenu, but with a property such as SelectedRowIndex and a method of SelectRowWithValue, this all implies a single selection rather than multiple (e.g. an array of selections).

I personally didn’t see anyway of accessing the DesktopPopUpMenu’s backend menu itself in order to implement multiple selections. Of course there’s true contextual menus supported by the PopupMenu, but what I needed was a conventional click instead of a right-click.

I don’t see anywhere where the DesktopPopupMenu states that multiple selections are supported, so I don’t really see this as a bug. So my feedback case from my point of view is a feature request.

P.S. Yes, I actually did go down the road of investigating using a unicode checkmark, but alas things definitely looked off-kilter as a result, especially when my app includes other single selection PopupMenus. Hence why I pivoted to the DesktopMenuItem instead which I can get to look pixel perfect in comparison to the native Xojo DesktopPopupMenu.

1 Like

LOL, great minds think alike! :wink: In my investigation I also explored using the DesktopBevelButton and although the menu itself is a ton easier and workable out of the box, I couldn’t get the BevelButton to look anything like the native Xojo DesktopPopupMenu. Yes, I could have explored maybe mimicking the look with images for the BevelButton, but alas, this breaks down and becomes a ton of work when you start thinking about resizing windows and buttons potentially expanding or shrinking.

I also explored to see if there were any third-party plugin solutions, but I couldn’t find anything that would have had the same look and feel as the native Xojo DesktopPopupMenu. Mind you, this was sort of a requirement for me as I’m shooting for a uniform look and feel within my app without a hodgepodge of similar widgets that look different.

Yes, I also thought about ‘faking it’. Guess I need to do this too.

I use NSPopupButton in Xcode a lot and I wanted to update an old Xojo project to make use of the multiple selections and sadly discovered that PopupMenu does not support multiple selection. I always thought Xojo was using native APIs.

Two reasons:
PopupMenu is not native or they didn’t implement the API fully.

It’s more likely that the macOS API did not support multi-item selection when it was first implemented and that it wasn’t updated when it became available or because it’s not possible on Windows/Linux.


Did a quick look and OSX 10.2 already had this functionality.
But I think you are right, Windows (not sure about Linux) doesn’t. So maybe that’s why it is not implemented.

In some of y apps, I replaced popupmenu by a listbox. That way I can have multiple selections.

1 Like