KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Prevent Listbox row from moving programmatically
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: May 26, 2016

Below is an utility method that will prevent rows from being moved in a listbox. The method should be called in the listbox's On Row Moved event

// Method: LB_PREVENT_ROW_MOVE
// Description: Prevents row move in array-based listboxes. Should be called in
// Listbox's On Row Moved event

//
// Parameters:
// $1 (Pointer) - Pointer to Listbox
C_POINTER($1;$LB)
C_POINTER($col)
C_LONGINT($oldRow;$newRow;$newRowInserted;$rowMovedTo;$i)
ARRAY TEXT($arrCols;0)
ARRAY TEXT($arrHdr;0)
ARRAY POINTER($arrColV;0)
ARRAY POINTER($arrHdrV;0)
ARRAY BOOLEAN($ColsVis;0)
ARRAY POINTER($Styles;0)

If (Count parameters>=1)
   $LB:=$1
   LISTBOX MOVED ROW NUMBER($LB->;$oldRow;$newRow)
   LISTBOX GET ARRAYS($LB->;$arrCols;$arrHdr;$arrColV;$arrHdrV;$ColsVis;$Styles)
   Case of
      : ($oldRow<$newRow)
        $newRowInserted:=$oldRow
        $rowMovedTo:=$newRow+1
        LISTBOX INSERT ROWS($LB->;$newRowInserted)
      : ($oldRow>$newRow)
        $newRowInserted:=$oldRow+1
        LISTBOX INSERT ROWS($LB->;$newRowInserted)
        $rowMovedTo:=$newRow
   End case

   For ($i;1;Size of array($arrColV))
      $col:=$arrColV{$i}
      $col->{$newRowInserted}:=$col->{$rowMovedTo}
   End for
   LISTBOX DELETE ROWS($LB->;$rowMovedTo)
End if


Example:

The code below shows a Listbox object's method. The code will prevent rows from being moved in the listbox, even if the Movable Rows property is checked.
// Listbox object method
Case of
: (Form event=On Row Moved)
  LB_PREVENT_ROW_MOVE (Self)
End case