Here is a simple way to allow the user to swap the elements within a scrollable area and Hierarchical List by dragging and dropping. All you need to do is to make sure that the following options are turned on in the Property List or Object Properties:
1. Dragable checkbox
2. Dropable checkbox
3. On Drop (form event) checkbox
Note: If you are using a Hierarchical List, make sure that every list item has a reference ID.
All that is left to do now is to add one of the following code into your object method.
` Object Method for Scrollable Area object
` Add Komoncharoensiri - 4D, Inc.
If (Form event=On Drop )
C_TEXT($TempElem) ` Type can be changed to an appropriate one.
$TempElem:=Self->{Drop position}
Self->{Drop position}:=Self->{Self->}
Self->{Self->}:=$TempElem
REDRAW(Self->)
End if
Example:
https://www.4d.com/Images/support/tt_2001_739-1.jpg
- The initial state of a scrollable area
https://www.4d.com/Images/support/tt_2001_739-2.jpg
- After "Company" is dragged and dropped on "Salary," "Company" is now listed as the element #3 and "Salary" is listed as the element #1.
` Object Method for Hierarchical List
` Add Komoncharoensiri - 4D, Inc.
C_POINTER($srcObject)
C_LONGINT($subList)
C_LONGINT($srcElement;$srcProcess)
C_LONGINT($itemRef1;$itemRef2)
C_BOOLEAN($expanded)
If (Form event=On Drop )
DRAG AND DROP PROPERTIES($srcObject;$srcElement;$srcProcess)
GET LIST ITEM(Self->;$srcElement;$itemRef1;$TempElem1;$subList;$expanded)
GET LIST ITEM(Self->;Drop position;$itemRef2;$TempElem2;$subList;$expanded)
SET LIST ITEM(Self->;$itemRef1;$TempElem2;$itemRef1;$subList;$expanded)
SET LIST ITEM(Self->;$itemRef2;$TempElem1;$itemRef2;$subList;$expanded)
REDRAW LIST(Self->)
End if
https://www.4d.com/Images/support/tt_2001_739-3.jpg
- The initial state of a hierarchical list
https://www.4d.com/Images/support/tt_2001_739-4.jpg
- After "4th Dimension" is dragged and dropped on "WebSTAR Server," "4th Dimension" is now listed as the element #4 and "WebSTAR Server" is listed as the element #1.