DragDrop and the DragDestination

zryip theSlug zryip.theslug at gmail.com
Thu Jan 20 20:59:16 EST 2011

On Fri, Jan 21, 2011 at 2:25 AM, Bob Sneidar <bobs at twft.com> wrote:
> Well I don't want to take a lot of anyone's time anymore. I thought it would be a simple matter to get the value of a cell in one dataGrid and put it into the cell of another, but this is proving to be a beatch.
> In your experiment 19, you use setDataOfLine to modify the value in the color column in the row dropped on to. Okay I get it, but since I am trying to put the value into the first empty cell in that column I am using setDataOfIndex because the cell may not be visible, should be no problem.
> But here's the problem: The destination data grid starts out empty, so all my calls to the index of anything is going to be zero. Even if I fudge the index to be one, if there is no objects for line 1, I cannot set the dataOfAnything.
> In retrospect, I think the way a datagrid should have been implemented is, there should ALWAYS be objects replicated for as many rows as are visible. This way, I could get and set values for any visible line without having to worry about this gotcha. I can see though that if someone scrolled the data grid, you would be faced with having to add more rows, and then would you delete them if the user scrolled up?
> Maybe the solution would be to have at least one empty row at the bottom of the datagrid so there would be objects to work with. Or else, the data grid api could be modified so that if I set the dataOfIndex or dataOfLine larger than dgNumberOfLines, it would insert as many blank lines as needed to get me there. Food for thought.
> I think what I will do, is instead of setting dgText to empty when I want to clear the datagrid, I will set the contents to a tab delimited list of empty lines for as many rows as are displayed. That will get around this issue for now.
> I hope people see my issue. It is like having a spreadsheet that constantly threw errors when I used an empty cell as a reference, simply because there was nothing in it.


on dragMove
   set the dragaction to "move"

   if (the dgDataControl of the target is empty) then
      addData ## Add a data line on the fly if the line not existing
   end if
end dragMove

on dragDrop
   local tTheLine, tTheColumn

   if (the dgDataControl of the target is empty) then pass dragDrop

   put the dgLine of the dgDataControl of the target into tTheLine
   put the dgColumn of the dgDataControl of the target into tTheColumn

   put the dragData["private"] into tTheDragData

   if (line 1 of tTheDragData is "Datagrid 1") then
      SetDataOfLine tTheLine, tTheColumn, line 2 of tTheDragData
      send "RefreshList" to me in 0 secs
   end if

end dragDrop

Some explanations:

1. In the dragMove, the lines are created on the fly if the
dgDataControl of the target is empty (so there is no line of data
under the mouse) So dropping a value in a cell is allowed with no

2. In dragDrop, a test is added:
if (the dgDataControl of the target is empty) then pass dragDrop

No more error should occur if the datagrid is empty

Best regards,
-Zryip TheSlug- wish you the best! 8)

More information about the Use-livecode mailing list