Drag and drop text between fields

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Drag and drop text between fields

Post by andyh1234 » Mon Sep 10, 2007 6:15 pm

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

Nigel
Posts: 5
Joined: Fri Sep 07, 2007 2:45 pm

Post by Nigel » Mon Sep 10, 2007 6:35 pm

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

andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Post by andyh1234 » Mon Sep 10, 2007 7:47 pm

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

andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Post by andyh1234 » Mon Sep 10, 2007 10:11 pm

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

Nigel
Posts: 5
Joined: Fri Sep 07, 2007 2:45 pm

Post by Nigel » Mon Sep 10, 2007 10:18 pm

Hi,

Just found an app I wrote which did this and has the same code as you so confirmation that that works.

Nigel

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

thank you

Post by reelstuff » Tue Sep 11, 2007 3:12 am

thank you for sharing, it really helps others to understand.

:lol:

Gus
Posts: 2
Joined: Tue Sep 18, 2007 6:35 pm

How to delete source line after drag and drop into target

Post by Gus » Thu Sep 20, 2007 6:13 pm

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 :-)

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Thu Sep 20, 2007 6:46 pm

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

Gus
Posts: 2
Joined: Tue Sep 18, 2007 6:35 pm

Post by Gus » Thu Sep 20, 2007 7:04 pm

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 :-)

Post Reply