LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Drag And Drop Element Of Array Of Clusters

Solved!
Go to solution

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:

 

  • Tests (array of):
    • Cluster:
      • Part Numbers (array of strings)
      • Regex (string)
      • Tasks (array of):
        • Cluster:
          • Task type
          • Base Channel,
          • Measurement Channel
          • Other Channels

 

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

 

--
Geoff Field, BE, CLAD, MIEAust
Professional geek, amateur stage-levelling gauge
0 Kudos
Message 1 of 6
(5,298 Views)
Solution
Accepted by topic author GeoffF

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,

Tom L.
Message 2 of 6
(5,284 Views)

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

--
Geoff Field, BE, CLAD, MIEAust
Professional geek, amateur stage-levelling gauge
0 Kudos
Message 3 of 6
(5,255 Views)

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

 

--
Geoff Field, BE, CLAD, MIEAust
Professional geek, amateur stage-levelling gauge
0 Kudos
Message 4 of 6
(5,251 Views)

Glad to help!

Tom L.
0 Kudos
Message 5 of 6
(5,238 Views)

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

 

--
Geoff Field, BE, CLAD, MIEAust
Professional geek, amateur stage-levelling gauge
0 Kudos
Message 6 of 6
(5,233 Views)