11-15-2013 12:44 AM
I have a project that includes an array of "tests", each of which is a cluster containing an array of "part numbers", a regular expression matching string and an array of "test tasks" (each of which, is in turn, a cluster of elements).
That is:
I'd like to be able to drag and drop to re-order the task array within an individual test. (It's a nice-to-have rather than an urgent request - more for my own learning than anything). For now, I've implemented "Move Up" and "Move Down" buttons.
The examples are fine for a single cluster that includes an array, or for an array of objects. As soon as we have an array of clusters, it's hard to access the individual elements within a specific cluster.
Has anybody successfully implemented drag and drop within such a setup?
Curiously,
Geoff
Solved! Go to Solution.
11-15-2013 02:27 AM - edited 11-15-2013 02:31 AM
Hello GeoffF,
This is definitely doable, and you can even use the standard start drag and drop methods/events, the tricky part is determining the array elements that are being selected on mouse up/mouse down and handling the swap manually. Luckily, there are a couple decent examples of how to do this out there already, I'd suggest you take a look at this one:
Community Example: Determine Clicked Array Element Index in LabVIEW
https://decibel.ni.com/content/docs/DOC-22434
That should give you the selected array indices, and then all you have to do is switch the elements around around in the drop event. I've attached a very basic demonstrative example that uses that code I just linked (you'll need to download that as well) and the events mentioned to swap two array elements. The attached code is just thrown together, you'll want to design something more robust and scalable for any sort of real use.
Regards,
11-17-2013 05:40 PM
Thanks for taking the time to reply, Outlaw.
It's almost what I'm after. I think what I need to do is to extract the control reference of the selected array of clusters WITHIN the array of clusters to be able to do what I need to do.
I should point out that my "Test" array is displayed one element at a time, with the array of "Tasks" displayed three at a time in a scrolling list. It's the "Tasks" I would like to drag-and-drop.
Fortunately, I have developed code to extract references to the elements within the cluster, so this shouldn't be too hard now.
Regards,
Geoff
11-17-2013 06:17 PM
...and now I've managed to implement pretty much exactly what I was after. I've even had a prompt from the "thrown together" code on how to make my "Move Up" and "Move Down" buttons less inefficient.
Thanks again Outlaw. You've been credited in my VI documentation, too.
Regards,
Geoff
11-17-2013 10:12 PM
Glad to help!
11-17-2013 10:34 PM - edited 11-17-2013 10:35 PM
Last post on this, I promise:
I noticed that the combo boxes and drop-downs in my "Task" cluster stopped responding correctly when the "Start Drag" method kicked in.
Accordingly, I had to add code to disable the "Start Drag" method when those specific elements were clicked. I simply compared the Mouse Down coordinates with the bounding rectangle of the elements (see the attached VI).
I also used the "scrollbar clicked" and "index clicked" outputs of the "Determine Clicked Array Index" VI to disable the "Start Drag" method so those parts of the element would work correctly.
(Not to mention using the "In Range and Coerce" function to ensure I was only dragging valid elements to valid locations.)
Regards,
Geoff