LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

listbox dragging problem

I have a listbox that I use to point to a cluster array. An event is generated when the user clicks on a list item. Then I use the new scalar value of the listbox as the index into the data array and display the corresponding array element. I would like to enable item dragging within the listbox so that the user can reorder the array. It seems that this cannot be handled as an event. In fact there seems to be no good way to unambiguously handle a dragged list item. The closest I can come is to check if the listbox item names change order each time the listbox changes value. But if I have two sequential items in my array that have the same name, there is no way to distinguish whether the user has simply clicked from one to the other or dragged one
of them to switch their positions.

The only workaround I can think of is to enforce unique listbox names. It might even be possible to hide this from the user if I simply append whitespace characters to enforce uniqueness. Does anyone have any other suggestions? Perhaps there is some way to monitor mouse down and up events while keeping track of the the list value. I'll have to do some more experimenting along these lines.

bb
0 Kudos
Message 1 of 7
(4,210 Views)
Hi BB,

I started think about this last night but got distracted before I had a chance to reply.

It sounds like you already solved you own problem by comparing the strings before and after.

If you hav a list box that has;

a
b
c
c
d
e

why do you want to know the user has swapped "c" with "c"?

If you really need to do this, watching for mouse clicks and the position is probably going to get you there.

But why?

Curious,

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 7
(4,209 Views)
The display names in my cluster array are not guaranteed to be unique. The name is just one element of a more complicated structure. If the names of two array elements are identical, other cluster componenents may not be.
0 Kudos
Message 3 of 7
(4,209 Views)
bb,

I would agree that enforcing unique names will probably be your best possibility here.

Randy Hoskin
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 4 of 7
(4,209 Views)
sorry to jump into an old thread, but I am faced with this same problem. I would like to use a multicolumn listbox to allow the user to sort some items in LV8.0.1. I see that the bug associated with dragging items in listboxes in executables is now fixed so I'm optimistic about a graceful solution. I am new to drag and drop in LV, but it would seem that it would be possible to get the index of an item dragged, and also the index of where it is dropped in the same listbox. If this is possible, I can reorder the array represented by the items in the listbox. Some pointers on how to do this would be great.

Based on the previous discussion here in this thread, it seems that the consensus was to check the order of the items in the listbox after the drop event, and then reorder the array as necessary. I can do this (the first column of my mclb is unique), but if it is possible to get the indeces, I'd like to do that instead.

Thanks,
Chris
0 Kudos
Message 5 of 7
(4,044 Views)
Chris,
Currently, it is not possible to get the indices of an element. You can, however, get the location of the mouse click in pixels and if you know the dimensions of one of the elements, you can figure out which item you've selected.
 
 
Chris C
Applications Engineering
National Instruments
0 Kudos
Message 6 of 7
(4,033 Views)
Thanks for getting back to me. It was a bit time sensitive, so I just went with a quick check of the order of the elements in the listbox, and then resort the array to match. As I said earlier, in this case I have unique elements in a column of the listbox, so it's easy to do. I'll keep in mind the use of the cursor position in the future. That should be pretty easy too, and I bet it would perform substantially better on larger arrays.

Thanks,
Chris
0 Kudos
Message 7 of 7
(4,027 Views)