GUI ScreenIO for Windows

 ScreenIO.com


How to Use Combobox Controls in Your Program

The definitions for a combobox reside in both the -3 and the -4 portions of the panel copybook.  The list associated with the combobox is in the -3 area, and the selected value (or the value typed in the associated edit control) is in the -4 area.  This makes a combobox very easy to use.

The copybook segments for a combobox are shown below:  Notice the comments explain much of what you need to use it.

 01  panel-3.
       .
       .
     05  MY-COMBOBOX-COMBOBOX.
*                         :
*                         : MAX is provided so your program
*                         : can know the maximum number of
*                         : elements in the table.
       10  MY-COMBOBOX-MAX     PIC 9(4) COMP-5 VALUE 10.
*                         :
*                         : SELECTORS: Single or Multiple.
*                         : SEL will contain one byte flags
*                         : for each entry in the list which is
*                         : set to 'S' when that list entry is
*                         : selected. You may "suggest" an entry
*                         : by setting this before display.
       10  MY-COMBOBOX-SELS VALUE LOW-VALUES.
         15  MY-COMBOBOX-SEL OCCURS 10 INDEXED MY-COMBOBOX-SDX
                                 PIC X.
           88  MY-COMBOBOX-SELECTED    VALUE 'S'.
           88  MY-COMBOBOX-NOTSEL      VALUE LOW-VALUE.
*                         :
*                         : This is the table of elements which
*                         : define the entries for this control.
       10  MY-COMBOBOX-TBL.
         15  DAT--13-40    PIC X(40) VALUE
                            'Alaska WashingtonOregon Montana'.
         15  DAT--53-60    PIC X(60) VALUE LOW-VALUES.
       10  FILLER REDEFINES MY-COMBOBOX-TBL.
         15  MY-COMBOBOX-ITM OCCURS 10 INDEXED MY-COMBOBOX-IDX.
           20  MY-COMBOBOX-VAL   PIC X(10).

  01  panel-4.
       .
       .
      05 MY-COMBOBOX           PIC X(10) VALUE SPACE.


You can load data to the list at runtime in a little perform loop, like this.  If you use the value in MY-COMBOBOX-MAX to terminate the perform, your code won't have to be modified if you change the number of elements in the list...

     PERFORM 
         VARYING MY-COMBOBOX-IDX FROM 1 BY 1
         UNTIL MY-COMBOBOX-IDX > MY-COMBOBOX-MAX
          .
          .
       MOVE mydata TO MY-COMBOBOX-VAL (MY-COMBOBOX-IDX)
     END-PERFORM

If you want to clear a previously loaded combobox, you should move LOW-VALUES to the table (MY-COMOBOBX-TBL in this example).  Do not move spaces unless you want a list of multiple blank entries to appear in the drop-down.  (Spaces are legal values in combo box entries).

If you want to have an item in the list appear selected when the combobox is activated, just set the selected byte for that item like this:

     SET MY-COMBOBOX-SDX TO MY-COMBOBOX-IDX
     SET MY-COMBOBOX-SELECTED (MY-COMBOBOX-SDX) TO TRUE

Alternatively, you can load data to the edit control portion of the combobox:

     MOVE mydata TO MY-COMBOBOX.

NOTE: You should always clear (move LOW-VALUES to) MY-COMBOBOX-SELS if you wish to clear selections made (or set) previously.  Otherwise, the system will select the item previously selected the next time you displayed this panel. This can be an annoyance for your users, and might cause data to "migrate" from record to record as they update successive records in a file.  The SELs over-ride any value you place in the edit control.


Now, call GUI ScreenIO to display your panel.  If the user changes MY-COMBOBOX by typing data or by selecting it from the list, the data will be found in this field when control returns from GUI ScreenIO.

You use the data just as you would data in any other field.  If you want to MOVE it to a different field, do this:

     MOVE MY-COMBOBOX TO mydata.

Incidentally, if you press the right mouse button while it's over a combobox's edit control, you can use the standard Windows editing facilities, as shown here.  This works in all edit controls, and it's automatic:

Related topics:


2000-2019 Norcom, all rights reserved 

TOC

Send feedback to Norcom