Skip to main content

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

  • March 26, 2020
  • 9 replies
  • 0 views

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.

9 replies

Fano Razafinimanana

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.

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


  • 0 replies
  • March 26, 2020

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

Thanks, Fano.  That would be great!


Fano Razafinimanana

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.

Hello Fran,

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


  • 0 replies
  • March 28, 2020

Hello Fran,

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

It is a listbox. I will attach screens on Monday. Thank you.

  • 0 replies
  • March 30, 2020
It is a listbox. I will attach screens on Monday. Thank you.

Please see attachment.  Thanks.


Fano Razafinimanana

Please see attachment.  Thanks.

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 replies
  • March 31, 2020

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.

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

 


  • 0 replies
  • March 31, 2020

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

 

Thanks, I will try both solutions!

  • 0 replies
  • March 31, 2020

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.

Thanks! I will try this!