Using PopupMenu.AddSeparator on Windows produces a row containing “-” which is selectable. So, my PopupMenu contains a row other than the rows I’ve added. This is bad.
Is there any way of adding a non-selectable separator on Windows? I realise that I can detect selection of an item whose text is “-” in the Change event but I would prefer not to have to do this.
This is tweaked code from my app: does it work for you?
dim t as new menuitem
dim m as menuitem
m= new MenuItem
t.append m
n= new MenuItem
n.Text = "test1"
m.append n
n= new MenuItem
n.Text = "-"
m.append n
n= new MenuItem
n.Text = "hello"
m.append n
n =t.PopUp
if n = nil then
else
...
Thanks for this, Jeff, but I’m after doing this in PopupMenus, not MenuItems. I’ve already got it working as non-selectable in MenuItems, but a PopupMenu is a different beast.
I use a subclassed popup menu with a ‘LastIndex’ property. In the change event, I check if me.Text = “-”, then I reset the ListIndex to LastIndex and exit. Otherwise, I continue and set LastIndex to ListIndex and raise a ‘Change’ event.
The section of code below for contextual menu is in the “MouseDown” event of “TextArea” in a Desktop application on Windows 7, Xojo 2014r2.1 and the separator is not selectable. (Not sure if this is whats being discussed here).
//
// Start of file.
//
If IsContextualClick then
dim base as new MenuItem
base.Append( new MenuItem( "Copy" ) ) '0
base.Append( new MenuItem( "Paste" ) ) '1
base.Append( new MenuItem( "Select All" ) ) '2
base.Append( new MenuItem( "Clear" ) ) '3
base.Append( new MenuItem( MenuItem.TextSeparator ) ) '4
base.Append( new MenuItem( "Find" ) ) '5
base.Append( new MenuItem( "Find Next" ) ) '6
...
...
...
End If
Of all the representations of Windows drop down menus here only one shows a separator, and since it scrolls, I am not even sure it is not some custom control.
The solution to reject the selection seems the best one.
[quote=137462:@Syed Hassan]The section of code below for contextual menu is in the “MouseDown” event of “TextArea” in a Desktop application on Windows 7, Xojo 2014r2.1 and the separator is not selectable. (Not sure if this is whats being discussed here).
//
// Start of file.
//
If IsContextualClick then
dim base as new MenuItem
base.Append( new MenuItem( "Copy" ) ) '0
base.Append( new MenuItem( "Paste" ) ) '1
base.Append( new MenuItem( "Select All" ) ) '2
base.Append( new MenuItem( "Clear" ) ) '3
base.Append( new MenuItem( MenuItem.TextSeparator ) ) '4
base.Append( new MenuItem( "Find" ) ) '5
base.Append( new MenuItem( "Find Next" ) ) '6
...
...
...
End If[/quote]
Please try to carefully read the original post. He’s not talking about menutiems
[quote=137464:@Jon Ogden]Please try to carefully read the original post. He’s not talking about menutiems
He is talking about the POPUPMENU control.[/quote]
The provided example shows a pop-up contextual menu at the physical place on the screen in the “TextArea” where the user does a right mouse click. (Hence the text in the initial post that “Not sure if this is whats being discussed here”).
I too confused the controls. based on the ‘separator’ mention.
Ive never once seen a read-only combo box with a separator in all the time I have been using Windows.
Quick Google about it shows its not ‘a basic feature’ by any means:
[quote=137473:@Jeff Tullin]I too confused the controls. based on the ‘separator’ mention.
Ive never once seen a read-only combo box with a separator in all the time I have been using Windows.
[/quote]
A PopUpMenu is not a read-only combo box. It’s slightly different…
[quote=137473:@Jeff Tullin]
but given that Xojo has a specific command to add one, you would expect it to work. :)[/quote]
And not everything works with all platforms given platform limitations. For example, on PopUpMenu controls, the right click does NOT work on a Mac. It does on Windows. But it does not work on Mac because OS X prevents it from working as part of the way the OS X UI is defined to work.
One thing I should note about this method, if you are using the keyboard up/down arrows to scroll through the list, it will stop when it gets to the separator. I haven’t put togther the solution just yet, but I am guessing you could set a flag in the keydown to determine if the up or down keys were entered, and skip over the separator accordingly.
Yes, I agree. We use popupmenus so only specific values can be chosen, and then finding that it’s actually specific values or a dash is somewhat irritating.
How do I make a suggestion for something to be added to the Language Reference? Is it via Feedback, or somewhere else?
[quote]One thing I should note about this method, if you are using the keyboard up/down arrows to scroll through the list, it will stop when it gets to the separator. I haven’t put togther the solution just yet, but I am guessing you could set a flag in the keydown to determine if the up or down keys were entered, and skip over the separator accordingly.
[/quote]
Yes, that’s a good idea. It’s this sort of thing which is frustrating: if there’s a function for something, it should work properly.