11-09-2010 06:56 AM
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.
11-09-2010 07:27 AM
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
11-09-2010 07:35 AM
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
11-09-2010 09:44 AM
Take a look at Array Point To Row/Col on LAVA.
11-09-2010 10:31 AM
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.
11-09-2010 11:09 AM
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.
11-09-2010 11:18 AM
@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.
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
11-09-2010 11:50 AM
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.
11-09-2010 01:02 PM
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
11-09-2010 02:15 PM
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.