Showing results for 
Search instead for 
Did you mean: 

Interesting way to detect array index from mouse position

Ever programmed something and then been surprised it works? This was the first time for me. Wrote a bit of code with the intention of identifying the array index clicked from the mouse position for use in a 'mouse down?' event and it worked first time. Then I went back and realised I had been half asleep and it doesn't even use the mouse position- but as if by magic it works! 🙂


VI snippet below. For some reason LabVIEW modifies the array reference when I create a snippet, so you'll need to change that array reference for one pointing to array 2. <= Anyone able to raise a CAR against this?




Message 1 of 6

The Array Element property must return the reference to the "ativated" element.  Quite useful in this situation.  But you actually also need to add in the Index Value just in case the index is not set to 0.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 6

In the past I've used this VI.  I think it is quite similar to yours and I could probably simplify based on what you have done.  One thing my VI does is it tries to take into account the scrollbar size if one is being shown for the array.

Message 3 of 6

Hi ToeCutter,


This would be expected behaviour as the 'ArrElem' refers to the active element of the array and hence you ar egetting the bounds and position of this active element on the front panel.


Thanks and Regards,

Thanks and Regards,

Message 4 of 6

Good and simple.

Take care of the label position and size, it can change the position of the control.

0 Kudos
Message 5 of 6

Exactly what I needed. I have an indicator (array) with 500 indicators showing high level test results ( red/yellow/green ). Detailed data set displayed based on last indicator selected. Had done this previously with an overlaid transparent boolean control but only with 25 locations.


Initially started by using the mouse position and array position but I could not get it to work ( windows 8/LV2013 ). The reported array position  is offset from the actual array position (as reported by mouse). Not using vert/horz scroll bars. Error is not small, it's off by a considerable amount ( 1/2 array size ). Also, array posiiton varies based on label position. Didn'tt understand why that was occurring so i started looking through the forums for clues. That's when I found your solution.


Thank you.

0 Kudos
Message 6 of 6