I have spent the last few hours experimenting with drag and drop. While I have written code that works it feels a clumsy and over complicated so I would appreciate any comments. The code below is in a behavior button used by two list fields. The aim is to allow the user to select complete lines/rows of text and drag them either in the same list (field) or across to a second field. Drag and drop should not occur if the field is locked. The code is here and I have attached a demo stack. Thanks
Code: Select all
local sSourceLineNo
local sNewLineNo
on dragEnter --sent to destination control
if the locktext of me is false then
set the dragAction to "copy"
else
set the dragAction to "none"
end if
pass dragEnter -- this causes the cursor to be displayed
end dragEnter
on dragMove --sent to destination control
set the hilitedlines of me to (word 2 of the mouseline)
end dragMove
On dragdrop --sent to destination control
if the locktext of me is false then
put the mouseline into tDroppedLine
put tDroppedLine
If the mouseline is empty then
put the dragData["text"] & cr before line 1 of me
put 1 into sNewLineNo
else
put cr & the dragData["text"] after the mouseline
put (word 2 of the mouseline) into sNewLineNo
end if
end if
end dragdrop
On DragStart --sent to source control
if the locktext of me is false then
put (word 2 of the mouseline) into sSourceLineNo
put line sSourceLineNo of me into tLine
set the dragData["text"] to tLine
end if
end DragStart
On DragEnd --sent to source control
-- clean up the source list
set the dragAction to "move"
If the dragDestination is the dragsource then
If sNewLineNo <= sSourceLineNo then
add one to sSourceLineNo
delete line sSourceLineNo of me
end if
if sNewLineNo > sSourceLineNo then
delete line sSourceLineNo of me
end if
else
-- dropped in a different control
delete line sSourceLineNo of me
end if
--pass DragEnd
end DragEnd