LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
I would like to be able to drag down a column in a DataGrid and get the sum of the values for those cells through which I've passed. As a starting point I am just trying to identify the start line and the end line of a 'columnar drag'. The following on DragStart handler will get the start line just fine:
on dragStart
put the dgDataControl of the target into theDataControl
if theDataControl is empty then pass dragStart
put the dgLine of the dgDataControl of the target into theLine
--answer theLIne
end dragStart
My difficulty comes in trying to get the last line of the drag. The following is one of a few attempts I have made but it doesn't seem to do the job:
on mouseRelease
put the dgDataControl of the target into theDataControl
if theDataControl is empty then pass mouseRelease
get the dgDragDrop of theDataControl
put it into theDropLine
answer theDropLine
end mouseRelease
I would greatly appreciate any suggestion for getting this second half to work. I think that once I cross that hurdle I will be able to do the rest. References to further documentation also appreciated.
When you say it doesn't seem to do the job what do you mean? Where does the code fail? Does mouseRelease get called? Is theDropLine always empty?
MouseRelease does get called but both 'it' and theDropLine were empty as far as I could tell. Either that or I don't know how to look at their contents. Is the dgDragDrop some kind of structure or array that I don't know how to access? I can see in the library something about the "dropped after index" but I'm not sure how to get to it.
My original approach was to get the dgLine from the dragStart and put it and the dgColumn in a global variable. Then in the mouseRelease event I got the dgLine again but it was always the same number as the one from the dragStart. Then I moved on to the code I first showed in this message. Should I go Back and look at that original approach again?
The following code for dragStart and mouseRelease in my Default Column button answers with the line I start the drag on, not the one I finish the drag on.
Larry
on dragStart
put the dgDataControl of the target into theDataControl
if theDataControl is empty then pass dragStart
put the dgLine of the dgDataControl of the target into theLine
--answer theLIne
end dragStart
on mouseRelease pMouseBtnNum
put the dgDataControl of the target into theDataControl
if theDataControl is empty then pass mouseRelease
put the dgLine of the dgDataControl of the target into theLine
answer theLine
pass mouseRelease
end mouseRelease
Trevor,
Here is my latest attempt. It is getting pretty convoluted but still doesn't give me what I want. If I start the drag on line 3 and release the mouse on line 8, the answer I get is field "Value 0003" rather than 0008
on dragStart
put the dgDataControl of the target into theDataControl
if theDataControl is empty then pass dragStart
put the dgLine of the dgDataControl of the target into theLine
--answer theLIne
end dragStart
on mouseRelease pMouseBtnNum
put the mouseControl into theControl
send mouseup to the target
pass mouseRelease
end mouseRelease
on mouseUp
put the mouseControl into theControl
answer the name theControl
pass mouseUp
end mouseUp
I just fiddled with this a bit and you need to use the drag messages to get it to work. The following code will print out the line you star on and the line you end on.
local sDataA
on dragStart
put the dgDataControl of the target into theDataControl
if theDataControl is empty then pass dragStart
put the dgLine of theDataControl into sDataA["start line"]
set the dragData["private"] to "tracking"
end dragStart
on dragEnter
## make sure all controls in data grid accep drop
set the dragAction to "move"
pass dragEnter
end dragEnter
on dragDrop
put the dragDestination into theControlDroppedOn
if theControlDroppedOn is not empty then
put the dgDataControl of theControlDroppedOn into theControlDroppedOn
if theControlDroppedOn is not empty then
put the dgLine of theControlDroppedOn into sDataA["end line"]
put printkeys(sDataA)
end if
end if
end dragDrop
function printkeys pArray
local theData
repeat for each key theKey in pArray
put theKey & ":" && pArray[theKey] & cr after theData
end repeat
return theData
end printkeys
Trevor,
I have a dumb question for you. At one point you put the dgLine of theDataControl into sDataA["start line"] and then later you put the dgLine of theControlDroppedOn into sDataA["end line"]. Why then, if you put a break point just before the printkeys, do you not see both the starting value and the ending value in sDataA? Am I not looking at it correctly?
Not sure. I never try to use the debugger during drag/drop operations as I've run into problems with everything locking up in the past. I just print out the data in the message box.