Page 1 of 1
Drag and drop text between fields
Posted: Mon Sep 10, 2007 6:15 pm
by andyh1234
Im sure I have seen this somewhere but cant for the life of me find it again.
If you have two list boxes, what is the code needed to allow a user to drag a line from one into the other.
I want the user to be able to select a line from a field, and then either use the 'add' button to add it into the other field or simply drag and drop it, but I cant find the code to do a drag and drop.
Thanks
Andy
Posted: Mon Sep 10, 2007 6:35 pm
by Nigel
you've probably already seen this but page 210 onwards of the user guide has snippets of drag and drop code that do more or less what you want.
regards
Nigel
Posted: Mon Sep 10, 2007 7:47 pm
by andyh1234
Thanks Nigel,
I had a look at that and it seemed to work fine for text fields, but as soon as you turned it into a list field the dragstart didnt seem to fire.
I was looking for a way for a user to be able to select a line from a list, and drag that over to another field, but the dragstart doesnt seem to fire at all.
If I do it from a text field it works fine, but then I dont get the list behaviour.
Andy
Posted: Mon Sep 10, 2007 10:11 pm
by andyh1234
Got it - ill post the result ive found here in case it helps others.
In the list field
on mousedown
set the dragData["text"] to the selectedtext of me
pass mousedown
end mousedown
In the targetfield
on dragdrop
put the dragdata["text"] into me
end dragdrop
Posted: Mon Sep 10, 2007 10:18 pm
by Nigel
Hi,
Just found an app I wrote which did this and has the same code as you so confirmation that that works.
Nigel
thank you
Posted: Tue Sep 11, 2007 3:12 am
by reelstuff
thank you for sharing, it really helps others to understand.

How to delete source line after drag and drop into target
Posted: Thu Sep 20, 2007 6:13 pm
by Gus
Hello:
I am evaluating Revolution and have been trying to perform a drag and drop operation where the field from the source is deleted after it is dropped in the target (moved). I am using two scrolling list fields called "List1" and List2" and the code I have thus far is as follows:
On Source scrolling list field:
-------------------------------------------------------------
on mousedown
set the dragData["text"] to the selectedtext of me
set locktext of field "List2" to false
pass mousedown
end mousedown
--------------------------------------------------------------
On Target Scrolling list field:
--------------------------------------------------------------
on dragdrop
put the dragdata["Text"] && CR after me
set the locktext of me to true
if the selectedline is empty then
-- do nothing
else
delete the selectedline
end if
end dragdrop
--------------------------------------------------------------
The problem is that I am left with an empty line in the source (List1).
Any ideas? Thank you

Posted: Thu Sep 20, 2007 6:46 pm
by Klaus
Hi Gus,
yep, looks like "delete the selectedline" only puts EMPTY into that line and not really deletes it.
Put this into the script of your target scrolling field:
Code: Select all
on dragdrop
put the dragdata["Text"] && CR after me
set the locktext of me to true
if the selectedline <> empty then
delete line (the hilitedline of fld "list1") of fld "list1"
end if
end dragdrop
Tested and works
Best from germany
Klaus
Posted: Thu Sep 20, 2007 7:04 pm
by Gus
That worked very well. Thank you so much. I am debating between RealBasic and Revolution. So far I have a very positive experience from the user formum with Revolution but I am finding the product a bit quirky.
Thanks again
