KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method for deleting selected records in a selection based list box
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: October 30, 2017

When using a selection based list box, it is important to understand that any changes (including record deletion) to the records from outside of the list box context will not automatically be updated in the list box. A new selection or the current selection must be reloaded in order to see the changes made to the reocords or selection.

Here is an utility method that will delete all selected records from the table and remove them from the list box view.

  // ----------------------------------------------------
  // Method: listboxDeleteSelectedRecords
  // Description
  // Delete all records selected in the selection based listbox
  //
  // Parameters
  // $1 - List Box Object Name
  // ----------------------------------------------------


C_TEXT($1)

If (Count parameters>=1)
  C_LONGINT($tableNum_l)
  C_TEXT($tableName_t;$highlightedSet_t)
  LISTBOX GET TABLE SOURCE(*;$1;$tableNum_l;$tableName_t;$highlightedSet_t)
  If ($tableNum_l>0)
    ARRAY LONGINT($recordNumber_al;0)
    LONGINT ARRAY FROM SELECTION(Table($tableNum_l)->;$recordNumber_al)
  End if

  ARRAY BOOLEAN($recordSelected_ab;0)
  BOOLEAN ARRAY FROM SET($recordSelected_ab;$highlightedSet_t)

  USE SET($highlightedSet_t)
  DELETE SELECTION(Table($tableNum_l)->)

  C_LONGINT($foundat_l)
  Repeat
    $foundat_l:=Find in array($recordSelected_ab;True)
    If ($foundat_l#-1)
      $recordSelected_ab{$foundat_l}:=False
      $foundat_l:=Find in array($recordNumber_al;$foundat_l)
      DELETE FROM ARRAY($recordNumber_al;$foundat_l)
    End if
  Until ($foundat_l=-1)

  CREATE SELECTION FROM ARRAY(Table($tableNum_l)->;$recordNumber_al)
End if