Announcement

Collapse
No announcement yet.

DropDown Combo Box Macro

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DropDown Combo Box Macro

    Dropdown Combo Box Macro

    When using a Dropdown Combo Box object, a user can type in a value which does not exist in the objects selection list. The macro descibed here provides an easy way to error the object if you do not want the user to be able to enter values which doe not exist as a selection.

    Why wouldn't I just use a DropDown List? A Dropdown Combo behaves like a text field, the user can use the Enter Key to trigger the navigation and validation of the object. With the DropDown List, this action occurs when the user makes a selection of an item.

    This macro (SCL Code) checks that the value entered for a combo box exists as one of the valid items or itemvalues for that object. If the item value is specified, then the proper selected item is set - (this works around the issue where once a value has been typed into the box, at least two characters must be typed in. This can be an issue for sequenced records).

    For more information on using macros within
    screen code see
    Using a Macro Library with Screen Code

    Macro Code (download file attachment...)
    Code:
    /*************************************************************************\
    	Macro: SCLCOMBOCK
    	
    	Paramters: None
    	
    	Purpose: 
    		SCL code which checks that the value entered for a 
    		combo box exists as one of the valid items or itemvalues 
    		for that object. If the item value is specified, then the 
    		proper selected item is set - (this works around the issue
    		where once a value has been typed into the box, at least
    		two characters must be typed in.  This is an issue for
    		sequenced records).
    \*************************************************************************/
    
    %macro sclcombock;
    	if _self_.selectedItem > '' then do;	
    	    if ^searchc(_self_.items,_self_.selectedItem) then do;
    	         n=searchc(_self_.itemValueList,_self_.selectedItem);
    	         if n then do;
    	            _self_.selectedindex=n;
    	        end;
    	        else do;
    	            _self_._errorOn();
    	            _self_.cperrormessage='The value specified is not one of the valid selections.';
    	            return;
    	        end;
    	    end;
    	end;
    %mend sclcombock;
    Calling The Macro
    The macro is then simply called from the objects onLostFocus method as shown in the following example:
    Code:
    /** OnLostFocus Method **/
    
    %include objfile;
    
    _OnLostFocus: method _self_:u:object;
    link createobj;
    ************************;
    ** Add user code here **;
    ************************;
    
    %sclcombock;
    
    endmethod;
    Attached Files
    Last edited by Ronni Rubenstein; 12-21-2009, 11:27 AM.
Working...
X