KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Maintaining a selection of records in a List Box while highlighting a new record
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: March 11, 2009

While displaying a selection of records in a 4D v11 SQL List Box and after adding a new record, how can you highlight that new record in the listbox and make it a member of the pre-existing selection? This tech tip illustrates one method of accomplishing that task.

In the method that displays the input form, create a variable to hold the "key" value field of the record being created:

READ WRITE([People])

INPUT FORM([People];"Input")
ADD RECORD([People];*)

C_STRING(61;vName_A61)
If(OK=1)
    vName_A61:=[People]Name
End if

UNLOAD RECORD([People])
READ ONLY([People])


At this point there will be no records in the selection for the current table. Now, use whatever QUERY and ORDER BY commands are necessary to recreate the listing to display in the listbox. Such as in the sample case:

READ ONLY([People])

ALL RECORDS([People])
ORDER BY([People];[People]Name;>)
COPY NAMED SELECTION([People];"NS_People")

USE NAMED SELECTION("NS_People")


Regarding the manipulation of set names for selected records, the examples in the New List Box Features in 4D v11 SQL Tech Note should help you feel comfortable doing that. The code below achieves the task of highlighting the new record in the new display of the list box:

CREATE EMPTY SET([People];"NS_Selected")

If (vName_A61#"")
    SET QUERY DESTINATION(Into set ;"NS_Selected")
    QUERY([People];[People]Name=vName_A61)
    SET QUERY DESTINATION(Into current selection )
    Names_aA61:=""
End if


Though the new record is highlighted, there is actually no "Selected Record". This is because the code uses SET QUERY DESTINATION(Into set;"NS_Selected").