Chapter Contents

Previous

Next
SAS/AF Software: Class Dictionary

Using the List Box Class

When list box items are selected, the list box is assigned a value. The value of the list box is the identifier of an SCL list containing three sublists: TEXT, ID, and ALL:
TEXT contains the text of the items selected from the list box in the order they were selected.
ID contains the row numbers of the selected items.
ALL contains all of the list box items, in the order they appear in the list box.

Generally, list boxes are populated after the INIT section runs unless a method that requires the list is called in the INIT section. Therefore, to manipulate lists in the INIT section of your program, you must call the _repopulate method to force the population in the INIT section before manipulating the lists.


Scrolling in a List Box

This example simulates scrolling in a list box. To scroll forward, issue the FORWARD command; to scroll backward, issue the BACKWARD command.

This example assumes you have entered the General Attributes window and selected Keys, Pmenu and commands from the Additional Attributes window and then selected Run main in Command Processing.

INIT:
   scrollcnt=4;
       /* Populate the list box */
   call notify('listbox1','_repopulate_');
       /* Get the list of items from ALL, the 
          third SCL list */
   lstid=getiteml(listbox1,3);
   listlen=listlen(lstid);
return;

MAIN:
if upcase(word(1))='FORWARD' then do;
   call notify('listbox1','_get_toprow_',
                toprow);
      /* LISTLEN is the number of items in
         the list box         */
      /* and SCROLLCNT is the number of items
         to scroll at once */
   if (toprow+scrollcnt)>listlen then
      _msg_='At bottom.';
   else call notify('listbox1','_set_toprow_',
                     toprow+scrollcnt);
end;

if upcase(word(1))='BACKWARD' then do;
   call notify('listbox1','_get_toprow_',toprow);
      /* LISTLEN is the number of items in
         the list box         */
      /* and SCROLLCNT is the number of items to
         scroll at once */
   if toprow=1 then
      _msg_='At top.';
   if (toprow-scrollcnt)<=0 then
      toprow=1;
   else
      toprow=toprow-scrollcnt;
   call notify('listbox1','_set_toprow_',toprow);
end;

call nextcmd();

return;

TERM:
return;


Retrieving Text and Row Numbers of Items in a List Box

This example uses the list box lists to retrieve the text and row numbers of items selected from the list box.

Assume the list box has been defined to allow multiple selections and that Maryland is in row 1 and North Carolina is in row 3.

   /* Deselect all items in the list box */
call notify ('listbox1', '_unselect_all_');

   /* Select North Carolina and Maryland from
      the list box entries */
call notify ('listbox1','_select_text_',
             'North Carolina');
call notify ('listbox1','_select_text_',
             'Maryland');

   /* Get the list ids of the TEXT (list 1) 
      and the ID (list 2) */
textlist=getiteml(listbox1,1);
numlist=getiteml(listbox1,2);

   /* Determine how many entries are 
      selected */
llen=listlen(textlist);
if llen<2 then
   _msg_="ERROR: a _selectText method failed";
else if llen>2 then
   _msg_="ERROR: the _unselectAll method 
          failed";
else
   do;

         /* Get the selected text values from
            the TEXT list */
      item1=getitemc(textlist,1);
      item2=getitemc(textlist,2);
      put "The following should be ITEM1=North Carolina 
         :" item1=;
      put "The following should be ITEM2=Maryland :
          " item2=;

         /* Get the selected row numbers from 
            the ID list */
      nitem1=getitemn(numlist,1);
      nitem2=getitemn(numlist,2);
      put "The following should be NITEM1=3 :
          " nitem1=;
      put "The following should be NITEM2=1 :
          " nitem2=;
   end;


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.