MenuItem.Checked not working in dynamically added menu

I am using Charles Yeoman’s WindowsMenu, which automatically maintains a “Window” menu, listing all open windows.

What bothers me, though, is that the current front window is not checked in the menu as it should be.

So I added code to set the Checked flag on the MenuItem. But it has no effect. Even with Xojo 2015r2.2, Checked=true does not make a checkmark appear in front of the menu title.

Is that a known issue, is there a work-around?

Anyone?

I’m not using checkmarks on the main menubar, just in a contextmenu. There I can switch the checkmark on and off and it displays correctly in the context menu. Xojo 2015r3, OSX 10.11 El Capitan.

Dim m As New MenuItem("a menu")

Dim l15 As New MenuItem l15.Text = imStrings.imLinkedDataBoxShowRegistrationOnDoubleClick l15.Name = "Listbox_ShowRegistration_OnDoubleClick" l15.Checked = SUPRT.ShowRegistration_OnDoubleClick m.append(l15) MenuIsThere=True

Call m.PopUp

[quote=222144:@Thomas Tempelmann]I am using Charles Yeoman’s WindowsMenu, which automatically maintains a “Window” menu, listing all open windows.

What bothers me, though, is that the current front window is not checked in the menu as it should be.

So I added code to set the Checked flag on the MenuItem. But it has no effect. Even with Xojo 2015r2.2, Checked=true does not make a checkmark appear in front of the menu title.

Is that a known issue, is there a work-around?[/quote]

I could not find the class you refer to, but quickly brew something, and the checked does show just fine :

[code] dim m,mNew as MenuItem
m=self.menubar
mNew=New MenuItem

mNew.text=“Window”
mNew.name=“Window”

For i As Integer = 0 To WindowCount - 1
Dim w As Window = Window(i)
If w <> Nil Then
mNew.Append(new menuitem(w.title))
End If
if w.title = self.title then mNew.Item(i).Checked = True
Next

m.Append mnew[/code]

Is it possible that somehow the class updates the menu after your checked is set ? What happens if you put that in a button ?

Michel, thanks for checking.
I’ll try your code and report back.
Which Xojo version are you trying this with, BTW? 2015r3, I suppose? 32 bit?

(BTW, the classes are inside macoslib. Or so I thought. Weird, where did I find them?)

Oliver, the issue only occurs with dynamically created menuitems for me. With those already in the Menubar it works.

Oh my! False alarm.

The Checked property works as expected.

However:

The MacWindowMenu code intercepts menu opening with its own installed handler (i.e. not through the EnableMenuItems event). And while that intercept code is called HandleCarbonEvent, it still works in Cocoa, surprisingly. And that code does its own setting of the checkmark, overriding my own attempts to set the checkmark. And that code is not working correctly in Cocoa any more, thereby always clearing the checkmark again.

So, case closed, and thanks for helping.

[quote=222548:@Thomas Tempelmann]Oh my! False alarm.

The Checked property works as expected.

However:

The MacWindowMenu code intercepts menu opening with its own installed handler (i.e. not through the EnableMenuItems event). And while that intercept code is called HandleCarbonEvent, it still works in Cocoa, surprisingly. And that code does its own setting of the checkmark, overriding my own attempts to set the checkmark. And that code is not working correctly in Cocoa any more, thereby always clearing the checkmark again.

So, case closed, and thanks for helping.[/quote]

Exactly what I was suspecting. Glad you found the insect :slight_smile: