Setting up QGrid for drag and drop

QGrid 1.8 supports two separate mechanisms for drag and drop:

QGrid's private mechanism has served reliably for years, but as it only works within an area or between QGrid areas, it does not allow interaction with other 4D objects. Our decision to support 4D's mechanism will lead to the deprecation of the private mechanism at some point in the future. Therefore, it is highly recommended to convert your existing projects to 4D's drag and drop mechanism rather sooner than later.

WARNING For as long as both mechanisms are available, you can activate either of them in a grid area. Keep in mind that an area may only use one mechanism. So, if both are activated for the same area, 4D's drag and drop will be used.

Working with 4D's drag and drop

To activate 4D's drag and drop mechanism for a QGrid area, use the area's draggable and/or droppable properties in 4D's form editor:

Here is an example object method of a droppable QGrid area that demonstrates how a drop operation is handled:

   // Object method of QGrid plug-in area xGrid
   // Accepts drag and drop from form object "list-box" in the same process

C_LONGINT($formEvent)
$formEvent:=Form event

Case of 
   : ($formEvent=On Drag Over)
      
      C_POINTER($srcObject)
      C_LONGINT($srcElement;$srcProcess)
      DRAG AND DROP PROPERTIES($srcObject;$srcElement;$srcProcess)
      
         // Reject drop by default
      C_LONGINT($0)
      $0:=-1
      
      If (($srcObject=OBJECT Get pointer(Object named;"list-box"))\
          & ($srcProcess=Current process))
         
         C_LONGINT($cellIndex;$err)
         $err:=QG_GetDropCell (xGrid;$cellIndex)
         If ($err=qg_noErr)
            
               // Accept drop
            $0:=0
            
         End if 
         
      End if 
      
   : ($formEvent=On Drop)
      
      C_POINTER($srcObject)
      C_LONGINT($srcElement;$srcProcess)
      DRAG AND DROP PROPERTIES($srcObject;$srcElement;$srcProcess)
      
      If (($srcObject=OBJECT Get pointer(Object named;"list-box"))\
          & ($srcProcess=Current process))
         
         C_LONGINT($cellIndex)
         $err:=QG_GetDropCell (xGrid;$cellIndex)
         If ($err=qg_noErr)
            
               // Handle the dropped item
            If ($cellIndex=-1)
               
                  // The dragged item was dropped past the last cell index
               
            Else 
               
                  // The dragged item was dropped on cell $cellIndex
               
            End if 
            
         End if 
         
      End if 
      
End case 

Study the demo database that is included in QGrid's distribution package for an example of drag and drop between a listbox and a grid area, using the new (4D's) mechanism.