Jump to content

Drag and Drop onto Subpanel


Recommended Posts

I am just guessing, but I'll bet this is done on purpose to avoid confusion about what happens when the subpanel is hosting a VI vs when it is not hosting a VI. Events on the subpanel tend to get routed to the VI it is hosting, so for consistency, events going to the middle of the subpanel tend to be dropped if there's nothing to receive them.

In practice, it probably doesn't save you much --- I can't think of a way to make arbitrary drag-n-drop work without having two procedures, one in the host VI that handles drag-n-drop when there is no subVI hosted and another in each of the subVIs to tell the host to change. Ug.

For the one in the host, I would suggest you should put a gray picture control over the top of the subpanel, use that as your drop target, and when it gets hit, hide the picture control. If you don't need to actually click on the subpanel, you could just make the picture control transparent and then leave it in play. But if you need to interact with it then any further drag-n-drop would need to be detected in the subVI.

You *might* be able to make it work using "mouse enter" on the subpanel and using that to trigger unhiding the picture control. I don't know how the timing on that would work out -- unhiding a control might not cause the events chain to reevaluate its drop target. Or it might. You'd have to test.

  • Like 1
Link to comment

In practice, it probably doesn't save you much --- I can't think of a way to make arbitrary drag-n-drop work without having two procedures, one in the host VI that handles drag-n-drop when there is no subVI hosted and another in each of the subVIs to tell the host to change. Ug.

Yeah, I need to drag data names from a tree onto different views. The two-step handler wouldn't bother me; I just need something that works for unfilled subpanels.

I'll try the suggestions you gave and report back on what works.

Link to comment

You *might* be able to make it work using "mouse enter" on the subpanel and using that to trigger unhiding the picture control.

I'm guessing this won't work reliably, as LV tends to miss mouse events for controls if the control is thin and you go through it quickly enough (which presumably would apply fairly regularly in a SP with a picture over it.

Link to comment

I'm guessing this won't work reliably, as LV tends to miss mouse events for controls if the control is thin and you go through it quickly enough (which presumably would apply fairly regularly in a SP with a picture over it.

Except that this isn't a thin control -- you're talking about a subpanel *region* being entered. LV "misses" enter/exit events when you move quickly passed a control and the mouse is never registered as being over that control, not when the mouse actually gets registered over the region. It doesn't matter how thin the region is. I'm not surprised that Stobber got this working.
Link to comment

I'm not surprised that Stobber got this working.

Just to clear the air, I never register for any events on the subpanel itself. I laid a transparent 2D Picture indicator over the panel and registered for Drag Enter and Drop on that. When Drag Started fires on the tree control, I make the transparent picture visible so it can fire events. When Drag Ended fires on the tree, I make the picture invisible again so it doesn't interfere with mouse clicks in the now-loaded subpanel VI. It works really well, and since I'm controlling the picture indicator's state in sync with the user's actions, there's no need to initialize anything before the container VI starts running.

Link to comment

Except that this isn't a thin control -- you're talking about a subpanel *region* being entered.

Now I see what you're saying. I missed that you were talking about UNhiding the control. Just so people are aware, I was talking about something like the attached VI.

...and since I'm controlling the picture indicator's state in sync with the user's actions, there's no need to initialize anything before the container VI starts running.

One thing to watch out for when dealing with things like this is the VI's Mouse Leave event. In your case, this is probably less of an issue because you're inside a control and you can monitor for the drag leave event as well, but you could still be bit (for instance, if another window decides to suddenly display itself under the cursor in mid-drag or if you have an ActiveX control in the middle, which I believe still triggers a Mouse Leave event). In such cases, you could be left in an unexpected state and writing code to account for such cases (at least by restoring the FP to a safe state so you can retry) can be difficult.

Mouse Enter Event.vi

Link to comment

One thing to watch out for when dealing with things like this is the VI's Mouse Leave event. In your case, this is probably less of an issue because you're inside a control and you can monitor for the drag leave event as well, but you could still be bit (for instance, if another window decides to suddenly display itself under the cursor in mid-drag or if you have an ActiveX control in the middle, which I believe still triggers a Mouse Leave event). In such cases, you could be left in an unexpected state and writing code to account for such cases (at least by restoring the FP to a safe state so you can retry) can be difficult.

The LV Help defines the Drag Ended event:

This event occurs after a drop operation, after the user cancels the drag and drop operation by pressing the <Esc> key, or the drag source window loses focus.

I take this to mean it'll fire if
anything
unexpected happens during the drag, which is why I'm using it to decide when to hide the picture indicator.

Link to comment

Actually, I never really had a chance to work with the drag events, so I didn't know that they handled this. With other event such as a mouse down followed by a mouse up handling such cases can be more problematic and I guess NI learned from the problem with the older events (or that something like that is easier for drag events).

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.