PopupMenu.AddSeparator on Windows

Hello,

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.

I think there are several - characters. Which one did you type?

But I can confirm that I have popups in my windows app and the separators are not selectable.
(Exe created with RB 2012 and tested on Windows 7)

Hi -

I’ve tested it with a very simple sample app. I’ve made a popup menu called PopupMenu1. In the Window.Open event I have put

PopupMenu1.AddRow("One") PopupMenu1.AddSeparator PopupMenu1.AddRow("Two")
On running that, the separator is selectable, on Windows 7.

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 just tested with RB 2007 under Windows 7, and I have the same problem with PopupMenus, but not MenuItems.

Yes it is.

You could try drawing a thick line along the bottom of one cell to set a visual marker if the method doesn’t work as expected in Windows.

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.

Yes - separators in pop-up menus are selectable. Just modify your code to reject the selection. Mark’s way looks to be a good one.

Ugh. Yes, OK, I’ll do that, but it’s very annoying; do ‘proper’ popup menu separators simply not exist on Windows?
Thanks
Hamish

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

VB6 apparently did separators: Menu seperators - Menus - VB 6 tutorial - developer Fusion
But it seems that .NET does not have that notion.

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

He is talking about the POPUPMENU control.

[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”).

No. A PopUpMenu is a specific control.

http://documentation.xojo.com/index.php/PopupMenu

A contextual menu that “pops” up is a similar but completely different animal.

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:

http://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=8&cad=rja&uact=8&ved=0CEcQFjAH&url=http%3A%2F%2Fwww.codeproject.com%2FArticles%2F18971%2FA-Separator-Combo-List-Box&ei=Mj5JVLD_CujB7AbT8oDgDA&usg=AFQjCNHZkNRnKZyvNeNIGUul1PLylSRWnA&sig2=5s-s8OoaHszbM8TNTfscmQ&bvm=bv.77880786,d.ZGU

but given that Xojo has a specific command to add one, you would expect it to work. :slight_smile:

[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.