KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: A technique for deleting a subset of records in a selection based list box
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: November 2, 2012

One of the challenges to replacing a default 4D output form with a selection based list box form is to give it the same default behavior as the when it comes to deleting a sub selection of records while maintaining the rest of the selection and its sort order.

The code below provide one technique to being the same result of deleting a sub selection of records to a selection based list box. It uses LONGINT ARRAY FROM SELECTION preserve the current selection and then allow the sub selection to be removed from the selection and deleted before the resulting selection is displayed in the list box.

If (Records in set("$LSTFRM_Set")>0)
   CONFIRM("Delete selected records?";"No";"Yes")
     //
     // Default response is "No" so "Yes" sets OK to zero
     //
   If (OK=0)
       // Delete the selected records and preserve the users selection of records
       // (
      ARRAY LONGINT($Selection_aL;0)
      LONGINT ARRAY FROM SELECTION(LSTFRM_TABLE_P->;$Selection_aL)

       // Delete the highlighted records from the longint array
       // (
      USE SET("$LSTFRM_Set")
      For ($Ndx;1;Records in set("$LSTFRM_Set"))
         GOTO SELECTED RECORD(LSTFRM_TABLE_P->;$Ndx)
         $SOA:=Find in array($Selection_aL;Record number(LSTFRM_TABLE_P->))
         DELETE FROM ARRAY($Selection_aL;$SOA)
      End for
      DELETE SELECTION(LSTFRM_TABLE_P->)
       // )

       // Create the selection of existing plus added records
       // (
      CREATE SELECTION FROM ARRAY(LSTFRM_TABLE_P->;$Selection_aL)
       // )

      REDRAW(ListForm_L)
       // )
   End if
End if