Drag and Drop between Data Grids

zryip theSlug zryip.theslug at gmail.com
Tue Dec 14 14:09:53 CST 2010


On Tue, Dec 14, 2010 at 5:45 PM, Bob Sneidar <bobs at twft.com> wrote:
> Well, I copied and pasted your scripts from your datagrids to mine. While I can drag, I do not seem to be able to drop. Yours work, mine do not. I got really flustered at that so I gave up for the night. I am going to have a fresh go at it today sometime.
>
> Permit me a bit of a rant: While Data Grids are pretty cool and do amazing things, I was kind of hoping for a native table field. Mastering Data Grids seems to take as much or more as it took to master everything else about LiveCode.

Bob,

1) In the datagrid source you need to have: the
dgTrackDragReorder[tTheIndex] set to false

If set to true, the datagrid tracks the move inside it. If set to
false you are allowed to move the data outside it.

Only this handler is required in the source datagrid:

on dragStart
   local tTheIndex, tTheDragData, tTheDataControl

   put the dgDataControl of the target into tTheDataControl

   if (tTheDataControl is empty) then pass dragStart -- Prevent the
move if no data control exists

   if (the dgHeader of the target is empty) then
      put the dgIndex of the dgDataControl of the target into tTheIndex
      set the dgDragImageIndex of me to tTheIndex

      ## Prepare the data to add in the datagrid 2
      put the dgDataOfIndex[tTheIndex] of me into tTheDragData
      combine tTheDragData using tab
      set the dragData["private"] to tTheDragData

      set the dgTrackDragReorder[tTheIndex] of me to false --
Important to move the data outside
   end if
end dragStart

2) In the destination, you need two handlers:

on dragMove
   set the dragaction to "copy"
end dragMove

The dragaction will allow the datagrid to get the data you drop.

on dragDrop
   local tTheNewData, tTheColOrder

   put "Col1" & cr & "Col2" into tTheColOrder
   put the dragData["private"] into tTheNewData
   send "AddLine tTheNewData, tTheColOrder" to me
end dragDrop

The dragDrop handler will receive the data dropped if the dragaction is allowed.


Best regards,
-- 
-Zryip TheSlug- wish you the best! 8)
http://www.aslugontheroad.co.cc



More information about the use-livecode mailing list