Jump to content

Drag-n-Drop


Recommended Posts

A question on Info-LV prompted me to answer with an example here on the Forums:

Dear all,

I'm trying to write a VI that implements simple drag and drop using event handlers.

This is a proof-of-concept thing at the moment, so it's practically useless, but bear with me...

I have two text controls and one text indicator. I want to be able to click on a control and drag the mouse over to the indicator - when I let go of the mouse button the contents of the control I dragged from are copied to the indicator.

I can get so far by using a Mouse Down event on each control, in which a ref to that control is written to a shift register. In the Mouse Up event on the indicator, I check whether the contents of the shift register represent a valid text control. If so, I copy the value of that control to the indicator. So far so good.

But - I want the VI to clear the reference if I drop anywhere other than in the indicator. I've tried adding a "<This VI>.Mouse Up" event, but this event always takes precedence over the indicator's Mouse Up event. I thought I might be able to get around this by re-ordering my events, but that makes no difference.

Any clues on how I might proceed? I imagine that dynamic event registration might hold the key, but as far as I can see I'd need to be able to dynamically register an event to handle either Mouse Up on the indicator or Mouse Up on the VI (with registration occuring on Mouse Over and Mouse Out events on the indicator) - but I'm not having much joy there because the VI and the indicator are different types.

Thanks in advance,

Simon

Here is a VI example (LV7.1) that acomplishes this. You need to register the Mouse Up event dynamically on the indicator that will receive the drop:

Link to comment

Michael,

Your solution is probably the best one for dragging the content from the control to the indicator :thumbup: but, in his original post, Simon said:

... I want the VI to clear the reference if I drop anywhere other than in the indicator...
and your solution does not do that. :thumbdown: The approach he posted to Info-LabVIEW:
...by dynamically registering the <This VI>.Mouse Up event, allocating it to a not-a-ref constant while the mouse is over the indicator.

, while too sketchy to be definitive, certainly has the potential to do so.

As a general programming point, tying the empty string constant to the frame of the while loop in your example does not ensure that the indicator is updated before the loop starts. :nono: In this particular case, operator response times are too long for the wiring to make any difference, but I have been bitten by this configuration when the machine response was too fast (commonly with my Running Global.vi utility). Your wiring only requires that the constant be read before the loop starts. (You can verify this by dragging the local variable upward and exposing the direct wiring from the constant to the frame of the loop.) To ensure that the indicator is updated before the loop starts, enclose the constant and the local variable in a single frame sequence. (The constant need not be in the sequence as long as the wire to the loop comes through the sequence, but I think putting both there is more explicit.)

Link to comment
Michael,

Your solution is probably the best one for dragging the content from the control to the indicator :thumbup: but, in his original post, Simon said: 

and your solution does not do that. :thumbdown: The approach he posted to Info-LabVIEW: 

, while too sketchy to be definitive, certainly has the potential to do so.

6005[/snapback]

Where is your improved solution then? Read my signature...

Link to comment
I believe there are plans to support drag and drop in the next version of LV

I have heard this too. It will be interesting to see the details. The fact is that there is already support for drag and drop - as evidenced by these examples. Mouse events are the building blocks on which drag and drop is built. But it would be nice to see the ability to drag objects (e.g. files) from outside LabVIEW into it. For example, it would be nice to be able to drag a JPG file from your file manager onto a picture control and be able to handle that event, opening the image and updating the picture control with it. (Mac OS X users will be familiar with this mode of updating a picture control.) That would make drag and drop in LabVIEW truly powerful.

I've attached my own solution to the problem I'd originally described. Enjoy!

Simon

Download File:post-924-1126252563.vi

Link to comment
...But it would be nice to see the ability to drag objects (e.g. files) from outside LabVIEW into it. For example, it would be nice to be able to drag a JPG file from your file manager onto a picture control and be able to handle that event, opening the image and updating the picture control with it...

Simon

6050[/snapback]

Simon

You can already do that very easily with almost no code. Overlay a path control over a picture control and catch the value change events. That's it.

post-121-1126286874.png?width=400

*Edit 1 * Note: the image I drag and drop, is actualy the image of the block diagram of the attached example.

*Edit 2 * Note: if you use firefox, drag and drop supported images directly from your browser to the VI (this is pretty cool).

Attached is an example (LV 7.1.1)

PJM

Download File:post-121-1126286915.vi

Link to comment
A question on Info-LV prompted me to answer with an example here on the Forums:

You need to register the Mouse Up event dynamically on the indicator that will receive the drop:

5996[/snapback]

True, but this works too (see attachment) You where playing with the wrong end of the drag'n

(The tails bad but the heads even worse)

You can ignore undefined Mouse Up events, just clear undefined Mouse Down events.

Control Mouse-Down's take priority over the vi Mouse-Down.

So your orignial, simpler idea was almost right.

-Bill

Download File:post-2910-1126465573.vi

Link to comment
True, but this works too (see attachment)  You where playing with the wrong end of the drag'n

(The tails bad but the heads even worse)

You can ignore undefined Mouse Up events, just clear undefined Mouse Down events.

Control Mouse-Down's take priority over the vi Mouse-Down. 

So your orignial, simpler idea was almost right.

-Bill

6097[/snapback]

Your solution is very nice. This is why I love the LAVA Forums... Great exchange of ideas. Keep it up guys... and gals.

Link to comment
  • 3 years later...

QUOTE (BChandler @ Sep 12 2005, 03:07 AM)

True, but this works too (see attachment) You where playing with the wrong end of the drag'n

(The tails bad but the heads even worse)

You can ignore undefined Mouse Up events, just clear undefined Mouse Down events.

Control Mouse-Down's take priority over the vi Mouse-Down.

So your orignial, simpler idea was almost right.

-Bill

The performance is very well.

:wub: I love it, a beautiful and simple soultion.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.