Super Contributor.
Super Contributor.
97 views

How can I change the way a listbox displays its contents?

Using a netexpress screen, we have a listbox that users may click entries from by clicking an X next to them.  However, the list display  is very long and always returns to the top of the list once they have clicked the entry, rather than staying where that  last selection was made.

0 Likes
7 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: How can I change the way a listbox displays its contents?

I think I have a demo of this somewhere in my archives. I'll attach it here when I'll find it.

–Ғɑɳօ
0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: How can I change the way a listbox displays its contents?

Thanks, Fano.  That would be great!

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: How can I change the way a listbox displays its contents?

Hello Fran,

Is it a list box or selection box? Can you please provide a screen capture of the behavior?

–Ғɑɳօ
0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: How can I change the way a listbox displays its contents?

It is a listbox. I will attach screens on Monday. Thank you. 🙂
0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: How can I change the way a listbox displays its contents?

Please see attachment.  Thanks.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: How can I change the way a listbox displays its contents?

Thanks for sharing the screen capture.

Based on what I see, the user clicks an item in the listbox. The DS screen does RETC to return to the COBOL program where the 'X' is added to the selected item. It returns to the DS screen and does REFRESH-OBJECT on the listbox with updated items. The REFRESH-OBJECT causes that no item is selected, so it always return to the top of the list.

In order to keep the last selected item visible on screen, you will need to have the item to be selected, and the listbox will show the selected item.

There is a function (GET-SELECTED-LIST-ITEM) to determine which item is selected, but there is unfortunately not a function to set a list item to be selected. Instead, you may achieve this with class library.

Here are the steps:

  1. Define these data items:
    CONFIG-FLAG                      C5     4.0           
    CONFIG-VALUE                     C5     4.0           
    
    LB-HANDLE                        C5     4.0           
    LB-OBJ                           OBJ-REF              
    DSLNKINDEX                       C5     4.0           
    
    LB-ITEM-SELECTED                 9      2.0 ​
  2. Load the class library and get the listbox handle from SCREENSET-INITIALIZED event:
    * Load the Class Library
         CALLOUT-PARAMETER 1 CONFIG-FLAG $NULL
         CALLOUT-PARAMETER 2 CONFIG-VALUE $NULL
         MOVE 15 CONFIG-FLAG
         MOVE 1 CONFIG-VALUE
         CALLOUT "dsrtcfg" 3 $PARMLIST
    *
    * Get handle of list box
         CLEAR-CALLOUT-PARAMETERS $NULL
         MOVE-OBJECT-HANDLE LB1 LB-HANDLE
         CALLOUT-PARAMETER 1 LB-HANDLE $NULL
         CALLOUT-PARAMETER 8 LB-OBJ $NULL
         INVOKE "listbox" "fromHandle" $PARMLIST​
  3. From the listbox event to handle the item selection
    1. Save the selected item's position
           MOVE $REGISTER LB-ITEM-SELECTED​
    2. Set the item to be selected again after RETC and REFRESH-OBJECT on listbox
           CLEAR-CALLOUT-PARAMETERS $NULL
           MOVE LB-ITEM-SELECTED DSLNKINDEX
           CALLOUT-PARAMETER 1 DSLNKINDEX $NULL
           INVOKE LB-OBJ "SetSelected" $PARMLIST​

Attached is my demo in case you want to review it.

–Ғɑɳօ
0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Re: How can I change the way a listbox displays its contents?

Hi frand1,

I use "slider-pos" and "user-event" and do not refresh the listbox.

SCREENSET-INITIALIZED

.

SUBCLASS-CONTROL
CALLOUT "SC" 0 CONFIG-VALUE *> sc.dll is the modifeid NE sample prog
USER-EVENT
IF= $EVENT-DATA 35000 F-ENTER
IF= $EVENT-DATA 34600 F-10
IF= $EVENT-DATA 50000 F-3
IF= $EVENT-DATA 34601 CUR-U
IF= $EVENT-DATA 50001 CUR-D

*LB-BOX

ITEM-SELECTED
GET-SELECTED-LIST-ITEM LB-BOX $EVENT-DATA 0
MOVE $EVENT-DATA SLIDER-POS

Now I do the changes and load  the listbox again and

MOVE SLIDER-POS $EVENT-DATA
SET-LIST-ITEM-STATE LB-BOX 1 $EVENT-DATA

and the cursor is on the selected, highlighthed line again.

Regards,

Georg

geozak_0-1585652892984.png

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.