As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Right-Click Context Menus

From sasCommunity
Jump to: navigation, search


You can make right-click context menus for any visual object that inherits from the widget class.

  • Step 1: Override the _popup method for your object.
  • Step 2: If your object has an _onpopup method, override that method as well.
  • Step 3: If your object has an _onpopup method, have it call the _popup method.
  • Step 4: In the _popup method, write code to create your list of choices.
  • Step 5: Pass your list of choices to the _childPopup method. (If you need to include choices from superclasses, call the super _popup method instead.)
  • Step 6: The user's selection will be an output parameter from the method you called in step 5. Write code that uses that selection number to carry out the user's choice.


Here is a simple example to create a context menu for a list box. This code will create two choices: Select All and Clear Selections.

dcl num rc;

*Step 1: overridden _popup method;
POPUP: method poplist:list sel:num;

   *Step 4: create list of selections;
   rc = insertc(poplist, "Select All", 1);
   rc = insertc(poplist, "Clear Selections", 2);

   *Step 5: call _childPopup method;

   *Step 6: determine what to do with the user's selection; 
   if (sel > 0) then do;
      if sel=1 then _self_._selectAll();
      else _self_.selectedindex=0;

*Step 2,3: overridden _onpopup method that calls the _popup method;
ONPOPUP: method;
   dcl list poplist=makelist();
   dcl num selection=0;
   *Alternatively Step 6 can go here;


Don't forget to include the correct method signature for your _onpopup method. For example, the treeview class takes a treenode object as a parameter to its _onpopup method;

onpopup: method treenode:sashelp.classes.treenode_c;

My above example was for overriding methods for an object (an instance of a class on your frame). If you want to create a class and override these methods, you will need to do a little arithmetic in your _popup method to take possible subclasses into consideration. See the online doc for an example of this: Widget Class: _popup