To download NI software, including the products shown below, visit ni.com/downloads.
This example shows how you can create a custom context menu in a LabVIEW Built TestStand User Interface. Unlike an application menu, a context menu is shown when right-clicking a UI pane and contains options relevant to the active pane. This example demonstrates creating a custom context menu when the user right clicks on a step in the sequence pane in the Full Featured UI example which ships with TestStand.
Before using this example, you will need to understand the following concepts of TestStand UI development:
If you are not familiar with these topics, review the following documents before using this example
To add a custom context menu to the TestStand Full Featured UI, this example implements the following changes:
Defining the Context Menu
Context menus in the TestStand UIs are generated in response to the CreateContextMenu event, which occurs when the user right clicks a TestStand UI control which supports context menus. Callback VIs, which execute when an event occurs, are defined in the Configure Event Callbacks.vi in the full-featured UI. In this example, we modify the SequenceView CreateContextMenu Event Callback.vi which defines the context menu that is generated when the user right clicks a sequence view control.
To create a context menu, the following TestStand UI API calls are required:
In this example, we replace the DefaultSequenceViewContextMenu_Set with different commands to change the context menu options:
In this example, two built-in commands (CommandKind_RunModeSkip and CommandKind_RunModeNormal, which set the selected step run mode to skip and normal, respectively) and a custom command are added to the context menu. To add a custom command, we use the CommandKind_Custom flag and set the userData to a unique value so that the selection can be identified when the user selects an option (details on this are in the next section). The name of the command in the menu is set using the Command.SetDisplayName method. In this example, the custom command is named "Set Limits", and allows the user to configure the limits for a test step directly.
Implementing the Custom Menu Item Functionality
Now that the menu has been modified, we need to add code to implement the custom command we created. The built-in commands CommandKind_RunModeSkip and CommandKind_RunModeNormal do not need any additional code since these are handled directly by the SequenceView Manager control. However, custom commands have no built-in functionality; they only trigger the PostCommandExecute event, where you can add code which executes when the menu item is selected.
The PostCommandExecute event is executed for any command the user selects, so it is necessary to check the UserData for the command to check that the menu item which triggered the event is indeed the custom command menu item (Set Limits):
Custom Context Menu - TS2016.zip
LabVIEW 2013 or Compatible
TestStand 2016 or Compatible
To use the example:
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.