PxPlus User Forum

Main Board => Discussions => Nomads => Topic started by: Mike Hatfield on October 16, 2024, 02:26:20 AM

Title: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: Mike Hatfield on October 16, 2024, 02:26:20 AM
I want to select a line or lines from a list box containing product sales information.
The list box is PROCESSed from invoice entry.
I only want the line in the list box to be added to the output from the process on a double click.
Currently a single click selects the line.
In the Nomads panel I have put an entry in the "When Entry is Selected from the List Box" to Perform a code section in the main program.
LINE_SELECTED:
  SELECTED++;
       LET ARG_3$(1,3)=STR(SELECTED:"000");
       LET ARG_3$=ARG_3$+LB.CTL'VALUE$+"!"

This works perfectly in sending the value of ARG_3$ back to the invoice program.
However, I don't want to select a line just by pointing the mouse and highlighting it.

I hope this makes sense.
Thanks
Title: Re: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: James Zukowski on October 16, 2024, 08:51:27 AM
At the beginning of your selection logic routine, check _EOM$ for $02$ to check for a double-click, and/or $0D$ for an ENTER key. This will filter out the single-click selections. Eg:
if pos(_EOM$=$020D$)=0 then return ! Only accept double-clicks and ENTERs
Title: Re: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: Jane Raymond on October 16, 2024, 09:26:09 AM
By default, list boxes require double clicks or Enter to select something. If it is doing a selection on a single click, then the Automatic (Signal all changes) attribute is set. You can filter as James suggested, where the single click is $01$.
Title: Re: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: Mike Hatfield on October 16, 2024, 09:14:25 PM
Thank you both.

Now that I can double click a row I want to leave it highlighted with a colour.
The aim is to select one or more rows from the list box and return them to the calling program for processing.
This I have achieved but I want to highlight the row(s) with a colour as it/they is/are selected.
What is the property to do this?

Thanks
Title: Re: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: Jane Raymond on October 17, 2024, 08:44:30 AM
Mike,
I'm not sure I follow. If the 'Multiple Selections' attribute is set for the list box, then all the rows selected will be highlighted automatically. (See example below.)
Title: Re: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: James Zukowski on October 17, 2024, 08:45:29 AM
Normally, I would simply set it up with the 'Multiple Selections' attribute set. That way, the user can use the standard Windows selections (click, ctrl-click, shift-click) to highlight as many as they want. Then when they tab out of the list, it triggers the selection logic and you can retrieve all of the entries at once.
Title: Re: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: Mike Hatfield on October 17, 2024, 07:03:56 PM
Again thank you both.

I am now more confused.
Clearly I am misunderstanding how this process works.


I want to highlight a selection of rows which will be returned to the calling program. These rows will be highlighted with a chosen colour for identity purposes. If I click on the row again I want the row to be unselected. I only want to pass the selected (highlighted rows) back to the calling progam.

Based on your previous replies these are the only ticked atrributes:
In Atttributes I have ticked Tab Stop
In Formatted ListBox Attributes I have ticked Multiple Selection
 
In Logic
I have a default Program
I have selected Perform in "When Entry is Selected from List Box"
This points to the code label "LINE SELECTED" in the default program.

I am unable to highlight multiple lines as per Jane's reply with a chosen colour.
If I could highlight multiple rows, how are those rows captured in the Perform above?
In my current code I can't remove a selected row from my returning string.

This is my Line Selected Code

The code creates a list of the selected rows, Adds a counter at the beginning of the list and a "!" separator between the selected rows so that I can parse it in the calling program.
00740 LINE_SELECTED:
00750  IF POS(_EOM$=$020D$) \
        THEN LET XXX$=LB.CTL'VALUE$;
             IF POS(XXX$=ARG_3$(4)) \
              THEN RETURN
00760  SELECTED++;
       LET ARG_3$(1,3)=STR(SELECTED:"000");
       LET ARG_3$=ARG_3$+STR(LB.CTL'CURRENTITEM:"000")+LB.CTL'VALUE$+"!"
00770  RETURN
Title: Re: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: James Zukowski on October 18, 2024, 09:31:59 AM
The When-Selected logic changes a bit when you move from double-click to multiple-selection. The _EOM$ values to check become $09$ for Tab and $0D$ for Enter. You may also consider including $00$ if someone simply clicks on another control on the panel (be sure to set 'Signal on Exit').

At that point, the LB$ value contains all of the selected entries, separated by the last character of LB$ (probably $00$). For efficiency, you may want to include the entry/row number in the line.

For example, if your list_box looks like:

001 | Item A | Description A
002 | Item Q | Description Q
003 | Item J | Description J

and lines 001 and 003 are selected, when leaving the list_box, LB$ would contain:

"001"+sep+"Item A"+sep+"Description A"+$00$+"003"+sep+"Item J"+sep+"Description J"+$00$

(Note: the "sep" may be redefined when defining the list_box by setting the 'Column Separator' on the format definition panel, and can be retrieved by Sep$=LB.Ctl'Sep$)

The row separator can be identified from:

EOL$=mid(LB$,-1)

The number of rows would then be:

N_Rows=pos(EOL$=LB$,1,0)

If you want the row separators to be "!" instead of the EOL, then:

LB$=sub(LB$,EOL$,"!")

And your selection routine becomes more like:

Line_Selected:
if pos(_EOM$=$00090D$)=0 then return
EOL$=mid(LB$,-1) ! get row separator character
N_Rows=pos(EOL$=LB$,1,0) ! determine # of rows selected (if needed)
LB$=sub(LB$,EOL$,"!") ! optional to replace the row separator
... ! any other row-based logic to apply
Arg_3$=LB$ ! to return to calling program
return

I've gone through other gyrations in the past to make the lists look and work spiffy. While I generally use Report Views instead of Formatted lists, the process is the same.

Good luck!
Title: Re: SELECTING A LINE OR LINES FROM A LIST BOX
Post by: Mike Hatfield on October 21, 2024, 05:12:38 PM
James,

Great explanation.
I shall try this and report back.
Thank you.