LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Drag and Drop in Tree using event structure

The issue that I have been having is that I want to be able to move an item in a tree to somewhere else in the same tree.  If I use no event structure actions it works fine, but in my case I want to validate the drop and verify that it can be placed.  So I used the Tree control "Drop" Action, I do my validation and then wire in a boolean to the accepted, the problem that I'm running into is that if true the item does move out of whiere it was at, but it doesn't apprear where I placed it, so essentially it just gets deleted from the tree.  I can programmatically place the item in the tree, however the issue with that is, I don't have a way to know if the user is moving it between two items or into an item as a child, As the Point to Row Column returns the Tag of the item your pointing at, or the same tag if you are trying to move the item below that same item.  Attached is the very basic code or filling a tree and allowing you to drag and drop items, but as you drag them they get deleted.  I don't understand what "Accepted?" means if it doesn't accept the Drop?  Thank you for any help and ideas.

Download All
0 Kudos
Message 1 of 17
(6,429 Views)

I don't have much experience with D&D in LV, but if I remember correctly, if you want to handle this yourself, you need to disable the built-in D&D on the tree and then implement the relevant logic yourself using the D&D events (detect the drag start and drop, looka at the data and if it matches, rearrange the tree).

 

I would suggest looking at the help and examples regarding the D&D events.


___________________
Try to take over the world!
0 Kudos
Message 2 of 17
(6,396 Views)

Thanks for the Reply.

 

You are correct, if I disable the drop function by wiring in a constant false to the Accepted terminal of the event "Drop" then the item will add, but the problem still persists where I can't tell if the user is dropping the item between 2 other items or into an item.  If anyone has any idea how to obtain that information, your help is greatly appreciated.

 

I have read what I can find on Drag and Drop and looked at all the examples I can find, but unable to find a solution that fits my need.

 

Thanks.

0 Kudos
Message 3 of 17
(6,343 Views)

I actually meant disabling the functionality in the context menu and then doing it yourself with the events, but if you disable it you probably won't get any of the drag events and will need the mouse down and up events.

 

I just did a quick search for "tree drag drop" and after a quick skim this seems to address this, although I haven't read it closely - http://forums.ni.com/t5/LabVIEW/Tree-Control-Drag-Drop-in-LabVIEW-8/m-p/305701#M158970

 

Does it help? If not, did you try a similar search?


___________________
Try to take over the world!
Message 4 of 17
(6,325 Views)

Hi Jcurran, 

 

I encourage you to take a look at this previous forum post and see if this solution works for you. 

http://forums.ni.com/t5/LabVIEW/How-can-I-only-drag-items-in-between-items-in-a-tree/td-p/1880109


Thanks,

Rita Prather
Software Product Manager
rita.prather@ni.com
National Instruments
Message 5 of 17
(6,322 Views)

Thanks TST for the link.  I hadn't seen that forum yet, but it had a lot of good information on how the events work. 

 

Also, it concluded with the last two post asking the same thing that I'm asking about getting the "drop between" information.  The posts were from 2010 and 2015, so I'm glad I'm not the only one out there who has tried this, but sad that I don't think that there is a work around for this particular desired feature.

 

Thanks again.

0 Kudos
Message 6 of 17
(6,307 Views)

Yeah as you've likely discovered, tree controls and drag and drop can be accomplished, but it usually involves a bunch of custom written code to handle how things are done.  Like most things in LabVIEW if you need the basics it is really easy, just enable drag and drop.  But if you need control over it, like being able to move things around, but only at the same level you are at, and to carry around the children of items moved, etc.

 

Let me reassure you that anything is possible, and you can accomplish what you want with the tree control, but it may take more coding than you expected.  Modern UIs, and good UX in general are difficult to accomplish in LabVIEW.

0 Kudos
Message 7 of 17
(6,285 Views)

I really needed this.  I searched the net looking for a solution, but I couldn't find one.

So I made my own.

"If you weren't supposed to push it, it wouldn't be a button."
Message 8 of 17
(4,381 Views)

I ran into the same issues being discussed here.

 

I chose to write a G-code implementation of drag/drop behavior for Tree/Listbox controls with a few notable improvements.

 

I had to get a little bit creative with how to implement my own custom horizontal bar.

I put a picture control behind transparent Tree/Listbox controls, and then populate/move the picture control as necessary.

 

This code is also particularly cool because you can use your cursor to select indent level when dropping between items on a tree control.

Moreover, the custom horizontal bar adds a visualization tilda to denote indent level when making this selection.

 

Code is open-source and on VIPM:

https://www.vipm.io/package/blue_origin_lib_better_drag_and_drop/

Message 9 of 17
(2,347 Views)

@brentjustice wrote:

 

I chose to write a G-code implementation of drag/drop behavior for Tree/Listbox controls with a few notable improvements.


Wow this is really cool, it will take me some time to dive in and understand how I can use this.  I will say that you tend to put lots of things on the palettes, and I think users generally feel more comfortable with a simplified API.  Maybe it is nit-picky but does the palette really need sub functions like the Move Items, Refresh, and Overwrite on the palette?  And on the topic of Palettes, where is the New Value and New Folder? 

 

I wonder if the tag creation process could be simplified by reading the existing reference and populating the items and values with what is already there.  But yeah this is pretty great stuff, thanks.

0 Kudos
Message 10 of 17
(2,314 Views)