### MenuBar CheckMenuItem

Example creating and accessing a Check MenuItem.
Define the CheckMenuItem
In the B4J Visual Designer, add a MenuBar view.
In the MenuItems JSON string, define like:
{Text: "_Show MQTT Console", Tag:"mnuUtilityShowMQTTConsole", EventName: "mnuUtilityShowMQTTConsole", Selected: False}
Important is to set the Tag as its being used to determine the menu item.
The full sub menu JSON string example:
{Text: "_Utility",
Children:
[
{Text: "_Show MQTT Console", Tag:"mnuUtilityShowMQTTConsole", EventName: "mnuUtilityShowMQTTConsole", Selected: False}
]
},
Define Global Map holding the Menu Items
`Sub Process_Globals
Private mbMain As MenuBar
Private menuItems As Map ' Map with all menu entries
...
End Sub`
Define a Sub to add the Menu Items to the Global Map
' Collect the menu items from the MainMenu Items list and add to a global map
' Example: CollectMenuItems(menuItems, mbMain.Menus)
`Private Sub CollectMenuItems(Menus As Map, Items As List)
For Each mi As MenuItem In Items
If mi.Tag <> Null And mi.Tag <> "" Then Menus.Put(mi.Tag, mi)
If mi Is Menu Then
Dim mn As Menu = mi
CollectMenuItems(Menus, mn.MenuItems)
End If
Next
End Sub`
Init the Map and populate with Menu Items from the MainMenu
' Get the menus as map
menuItems.Initialize
CollectMenuItems(menuItems, mbMain.Menus)
Handle the Menu Item Selection
' Show or close the mqtt console
`Sub mnuUtilityShowMQTTConsole_Action
Dim cmi As CheckMenuItem = menuItems.Get("mnuUtilityShowMQTTConsole")
If cmi.Selected Then
mqttConsoleForm.ShowForm
Else
mqttConsoleForm.CloseForm
End If
End Sub`

Changed: , Category: Menu, File: T6C220M1617.htm, ID: 1617