Run-Time Shortcut Menu
Here we are going to discuss about creating run-time shortcut menu for a control programmatically. As a continuation to one of my previous posts, the control that we will consider here will again be a multicolumn listbox. We will see how to create a runtime shortcut menu and then insert the selected menu item into the corresponding cell as shown below.
To get started with, follow the instructions as shown below.
- Place a Multicolumn Listbox control on the front panel and initialize it as required.
- In the block diagram, place an event structure inside the while loop.
- Create a Shortcut Menu Activation? event for Multicolumn Listbox control. This is a filter type event which will be generated when the user right-clicks on the control to display the shortcut menu.
- To delete the default shortcut menu items, place a Delete Menu Items function.
- Use Insert Menu Items function to add menu items of your choice. In case of single menu item, connect a string constant to item names input. In case of multiple menu items, connect a string array constant to item names input. Also connect the menu reference input as shown below.
- Next to insert the selected menu item into the cell of multicolumn listbox, create a Shortcut Menu Selection?(User) event for Multicolumn Listbox control.
- Obtain the selected menu item from Item Tag event data field.
- Obtain the cell position(row,column) using the invoke node and insert the menu item into the corresponding cell as shown below.