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?
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?
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…
Here are the logistics to pull this off via the various PopupMenu events…
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.
As a followup, I just created Feedback #72047 so that maybe one day Xojo can enhance the DesktopPopupMenu to support multiple selections.
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
MyPopupMenu.AddRow(item)
Next
I’d call this a bug then since DesktopMenuItems should be supported.
A workaround could be to use the 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.
LOL, great minds think alike! 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.