LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way of determining what element in an array is being clicked on?

Hi all.  I would like to setup an event to determine what element in an array is being clicked on/hovered over.  I think I tried this before and found it wasn't working due to limitations of LV 7.0.  If this code already exists, it would be great if I don't have to do a scavenger hunt for the solution.

 

I think one possibility I nixed was to use the refnum of the elements to determine which one it is.  IIRC, this is not possible because the refnum of the element is for the edit box only.

 

The second possiblity is to get the on click event, and somehow determine which element in the array it is.  This doesn't sound too difficult as it should be a simple calculation, but may get in to some hairryness based on if the indicies are visible or not, and if I am using a new or old array with new or old control (calc would change based on boarder size of the controls).  I might just simplify it by removing indicies and using older control set which has minimal boarder size.

 

And just for fun, can I force a tool tip to show up?

 

Thanks all,

 

 

A

 

Using LV7.0 on WinXP.

0 Kudos
Message 1 of 11
(4,062 Views)

The was an old thread where an NI person posted a link to an example in the community that did what you outlined but did not take into concideration the array index.

 

If you really want to make it robust then you have to take into concideration font size changes and for that purpose use teh Get Text Rectangle from the picture palette.

 

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 11
(4,047 Views)

Just remebered...

 

If you use a cluster on the GUI then you can have an event for each element or use the ref returned by the event to figure out which one it was.

 

I think you could do that in LV 7

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 11
(4,042 Views)

Take a look at Array Point To Row/Col on LAVA.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 4 of 11
(4,018 Views)

Its possible that it is the solution, but I don't have 7.1.1, So I just made my own.  Here it is here with a test VI.

 

BTW, I would post more code and examples here but my libraries are quite large and I would like to make them into .llb files before I do so.  Maybe in the near future, I'll blog about my exploits in LV and make the libraries available.  I'm sure I've hit apon a lot of things that have been wondered about but just ignored/bypassed.

Download All
Message 5 of 11
(3,996 Views)

 


Been bitten by LabVIEW wrote:


I think one possibility I nixed was to use the refnum of the elements to determine which one it is.  IIRC, this is not possible because the refnum of the element is for the edit box only.


Using LV7.0 on WinXP.


This is indeed possible, at least in the newer versions I use.

 

Take the array refnum from the click event data terminal and get a reference to the array element.  This refers to the element that was clicked, but you do need to work out how to get the index.  My method is to use property nodes to get the screen position and size of the element and the screen position and size of the array, as well as the array's Visible Index property. For each direction, take the quotient of the relative position of the element (account for padding!) over the size of an element.

 

I suspect that taking the mouse coords and comparing to the array's sizes in pixels is similar, although I trust my method for events that don't have mouseclicks (what coords does Array:shortcut menu selection(User) return if you used the keyboard?)

 

Here's an old version I happened to have open.  I've posted about this before, I suspect I have a clearer version in my gallery.  I use this method in my example code contest entry to work out which square of the chessboard is clicked.

 

array ref to indices.png

 

-Barrett
CLD
Message 6 of 11
(3,983 Views)

@blawson wrote:

 


@Been bitten by LabVIEW wrote:


I think one possibility I nixed was to use the refnum of the elements to determine which one it is.  IIRC, this is not possible because the refnum of the element is for the edit box only.


Using LV7.0 on WinXP.


This is indeed possible, at least in the newer versions I use.

 

Take the array refnum from the click event data terminal and get a reference to the array element.  This refers to the element that was clicked, but you do need to work out how to get the index.  My method is to use property nodes to get the screen position and size of the element and the screen position and size of the array, as well as the array's Visible Index property. For each direction, take the quotient of the relative position of the element (account for padding!) over the size of an element.

 

I suspect that taking the mouse coords and comparing to the array's sizes in pixels is similar, although I trust my method for events that don't have mouseclicks (what coords does Array:shortcut menu selection(User) return if you used the keyboard?)

 

Here's an old version I happened to have open.  I've posted about this before, I suspect I have a clearer version in my gallery.  I use this method in my example code contest entry to work out which square of the chessboard is clicked.

 

array ref to indices.png

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Thank you for that one!

 

I am currently "locked up behind a down-rev fence" (working an old app in an old version) so I had not heard of that.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 11
(3,977 Views)

I don't know what the earliest version this works in, so please try it out and see.  This behavior of array references is basically undocumented and I only found it out because someone pointed it out to me on here a while ago in a thread about array/element refs.

 

by old version on the snippet I meant an early version of the algorithm, not LV version.

-Barrett
CLD
0 Kudos
Message 8 of 11
(3,965 Views)

Might work.  But I forgot to stipulate that the control could be an indicator or disabled.  I did think about using that method, however as an indicator or disabled, there would not be an active edit box.

 

Nice though.

 

 

A

0 Kudos
Message 9 of 11
(3,953 Views)

it works in both of those cases.  I wire the refnum inside the event case to that subVI, see below.  This works for any array event that supplies a refnum.  If you just wire a plain reference to that code, you get the topleft element in a selection.

 

event case refnum.png

-Barrett
CLD
0 Kudos
Message 10 of 11
(3,933 Views)