How to: Use the ribbon's commands in a context menu
Give a form, an Access control, or a WKL grid a context menu with the same commands as the ribbon, without writing code that builds command bars.
Requires WKL Forms Object Library 1.49 or later; EnsureMenus and images from the database's image
gallery in context menus require 1.53 or later.
Solution overview
The Context menus page of the ribbon designer builds context menus from the model's commands:
entries, submenus, and separators. The runtime creates them as command bars each time a ribbon of
the database loads. Set the menu name as the Shortcut Menu Bar property of a form or control, or
as the ShortcutMenuBar property of a WklGrid, WklTreeList, or WklTreeView.
Implementation
In the designer, on the Context menus page, click Context menu (name it ctxCustomers),
then Entry for each command and Separator between groups of entries. On the form
frmCustomers, set Shortcut Menu Bar to ctxCustomers. For a grid:
Private Sub Form_Load()
Me!Grid1.Object.ShortcutMenuBar = "ctxCustomers"
End Sub
Remarks
- Entries are shown and enabled the same way as their commands: the command's condition and the values set in code (
Visible,Enabled,Label) apply, andInvalidaterebuilds the menus. - The menus are temporary command bars: they disappear when the database closes and are rebuilt when a ribbon of the database loads. A database whose model has context menus but no ribbon needs one call at startup:
CreateObject("WklForms.Ribbon").EnsureMenusin theForm_Loadevent of the startup form. - Office images (
imageMso) appear in the entries, and so do images from the database's gallery (16 × 16 pixels on the menu color). - To set the menu on many forms and controls at once, use the Assignments page; see How to: Assign context menus to forms, reports and controls.
- Toggle buttons and split buttons exist only on the ribbon.