Page 1 of 1
Drag inside a DataGrid
Posted: Sun Mar 28, 2010 1:28 am
by lohill
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:
Code: Select all
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:
Code: Select all
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.
Thanks,
Larry
Re: Drag inside a DataGrid
Posted: Mon Mar 29, 2010 3:00 pm
by trevordevore
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?
Re: Drag inside a DataGrid
Posted: Mon Mar 29, 2010 6:15 pm
by lohill
Trevor,
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.
Larry
Re: Drag inside a DataGrid
Posted: Mon Mar 29, 2010 6:20 pm
by trevordevore
dgDragDrop is a message that is sent, not a property of any control. Have you tried getting the dgLine of theDataControl?
Re: Drag inside a DataGrid
Posted: Mon Mar 29, 2010 6:45 pm
by lohill
Trevor,
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?
Larry
Re: Drag inside a DataGrid
Posted: Mon Mar 29, 2010 6:59 pm
by lohill
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
Code: Select all
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
Larry
Re: Drag inside a DataGrid
Posted: Mon Mar 29, 2010 7:06 pm
by trevordevore
The mouseRelease message is sent to the control you initially clicked on. What if you check the mouseControl rather than the target?
Re: Drag inside a DataGrid
Posted: Mon Mar 29, 2010 11:01 pm
by lohill
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
Code: Select all
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
Any more ideas?
Thanks,
Larry
Re: Drag inside a DataGrid
Posted: Tue Mar 30, 2010 4:11 pm
by trevordevore
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.
Code: Select all
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
Re: Drag inside a DataGrid
Posted: Tue Mar 30, 2010 5:51 pm
by lohill
Thanks Trevor. That certainly does work. All I have to do now is figure out how and why.
Larry
Re: Drag inside a DataGrid
Posted: Tue Mar 30, 2010 7:03 pm
by lohill
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?
Thanks for your help, even if I am a bit dense.
Larry
Re: Drag inside a DataGrid
Posted: Tue Mar 30, 2010 7:05 pm
by trevordevore
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.