Jump to content

Tree Control Drag & Drop in LabVIEW 8


Jim Kring

Recommended Posts

I've got some concerns with drag and drop events and how they relate to the tree control. Here is a simple use case: drag and drop nodes in a tree control. In order to do anything useful beyond the degenerate case of allowing all nodes to be dragged and dropped on any other node, I need to know the Source Tag and the Target Tag (to both validate and process these events, I need to know which item was dragged and dropped onto which other item). In LabVIEW 7.1 Source Tag and Target Tag are available as event data. However, in LabVIEW 8.0 the new control drag and drop events supersede the tree control drag and drop events (the tree drag and drop events have been depreciated and a warning dialog will be displayed when opening 7.1 code that calls these events). OK, here is the problem... there are no longer Source Tag and Target Tag event data in any of the LabVIEW 8.0 tree control drag and drop events. I have found a work-around by writing a routine that calculates which element the mouse is hovering over, but this is very non-direct and a bit of a kludge. Another issue is that the source item disappears from the tree control after the drop event is processed. This is not the end of the world (I can recreate the deleted node and child nodes), but it is still a bit of a pain and I believe that this is a bug.

So, am I off-track? Any thoughts?

(I've cross-posted this question to the NI Forums, to possibly get a resonse from someone at NI)

Link to comment

I got a response from the developer at NI, who worked on the new drag and drop feature. This addresses all of my questions. Also, it was great to learn of the new Point to Row Column method of the Tree Control -- this is also present in Listboxes and Multi-column Listboxes, too! That's a feature that's been needed for quite some time.

First of all, as the developer of drag and drop in LabVIEW 8.0, thank you for using my feature. Implementing this was a big challenge, especially since drag and drop was so limited in 7.1. Using drag and drop events is harder than it used to be. I apolgize for that. However, I think that you will see that the change was justified, and that we have ways to do virtually everything you could do in 7.1.

First, let me explain why we changed the drag and drop events.

In 7.1, drag and drop was very limited, and we only had events for drag and drop in a tree control. This meant that we could expose more information in the event structure. For example, 'source tag' and 'destination tag' both make sense if your drag source and target are both tree controls (or, technically, the same tree control).

In 8.0, drag and drop is much more general: you can drag from one tree to another; you can drag from any control to any other control; you can drag from one VI to another; a drag target can accept or decline all kinds of data; and you can register for events for all of these behaviors.

This reduced what we could expose in the event structure. Suddenly in 8.0, 'source tag' and 'destination tag' *don't* make sense, because your drag source and drag target could be *anything*.

I understand that this makes your use case harder -- but it makes many, many more uses possible.

Now, let's talk about your use case: filtering tree drag and drop like you did in 7.1.

In the tree's popup menu, there's an option called "Allow Drag/Drop Outside Control". Turn this off, and the tree won't be able to drag tree items to other controls, or accept drags from other controls (in other words, it'll behave like it did in 7.1).

To get the destination tag, use the "Point to Row Column" method on the tree control. Just pass it the point that you get from the drag/drop event. [1]

To get the source tag, use the LV_TREE_TAG data from the "Get Drag Drop Data" primitive. This is the source tag. (Alternately, you could cache the source tag in the "Drag Starting" event.)

Finally let's address your last comment:

Another issue is that the source item disappears from the tree control after the drop event is processed. This is not the end of the world (I can recreate the deleted node and child nodes), but it is still a bit of a pain and I believe that this is a bug.

I uploaded a test VI with a tree and a couple of the new drag/drop events: << link >>

If you run it and drop item 'c' on item 'a', item 'c' does indeed go bye-bye.

Why?

First, let's examine the built-in LV behavior for tree drag.

When you drop 'c' onto 'a' at edit time, LV does its normal built-in behavior for the tree's drag and drop.

That built-in behavior actually involves two steps:

Step 1: We update the drag source by deleting 'c'.

Step 2: We update the drag target by adding 'c' under 'a'.

And yes, 'source' and 'target' are the same thing: the tree control.

Certain drag/drop user events override built-in LabVIEW drag/drop behaviors.

More specifically:

* If you register for "Drag Source Update" on a drag source, LV will no longer do its built-in behavior for updating the drag source. Instead, LV leaves that entirely up to you.

* If you register for "Drop" on a drag target, LV will no longer do its built-in behavior for updating the target. Instead, LV leaves that entirely up to you.

This sample VI has registered for "Drop", and so at run time step 2 doesn't happen. If you register for the "Drop" event, you have to implement that Drop behavior yourself, in G.

I hope this clarifies things a little bit, and I hope that you will continue working with drag and drop. I know that it's not the easiest feature in the world to use, so any suggestions are appreciated.

[1] A quick note about what you said:

I have found a work-around by writing a routine that calculates which element the mouse is hovering over, but this is very non-direct and a bit of a kludge.

I don't think this is a kludge at all. In fact this is exactly what LabVIEW was doing internally before to determine if you were in droppable spot.

Link to comment

Here is a quick update: there is a good discussion going on the cross posting I made to the NI forums. I got some very useful information from Jeff and Darren, two NI developers, including some information on some vi.lib/tree/ VIs in 7.x that provide very useful functionality, including that provided by the "Point to Row Column" tree method of 8.x.

Link to comment
  • 10 months later...

I ran in the same problem today. The "point to row" method can fix a lot, but I still have not found a solution how to figure out, whether I dropped an element ON or UNDER an other element, except with manually calculating the cursor position and the element sizes, which seems to be to much work for that purpose.

I'm a little bit disappointed that it's much harder in LV 8.x to create a user interface with a drag & drop tree than in LV 7.1 ...

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
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.