Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

How To Return the Index of a Mouse-Select Array Element

 Overview

This example shows how to determine which element of an array a user has clicked on the front panel.


Description

This example shows how to determine which element of an array a user has clicked on the front panel. It uses an even structure to determine when a user has clicked on an array element. Then using the coordinates of the mouse cursor and the dimensions of the array, it calculates which element was clicked on.


Requirements: LabVIEW 2012 (or compatible). Hardware: none.


Steps to Implement or Execute Code:

  1. 1. Run the VI.
    2. Click on a cell in the array.
    3. Compare the result from the indicator "Clicked Index".

Additional Information or References:

 

How To Return the Index of a Mouse-Select Array Element FP.png

 

How To Return the Index of a Mouse-Select Array Element BD.png


 

**This document has been updated to meet the current required format for the NI Code Exchange.**



Comments
Member ANCO_Engineers
Member

Thank you for sharing...works great!

M.S.
Member fmlmf
Member

This does not work correctly if you have a label or caption on displayed on the array. To fix this, use the "Master Bounds Rect" property to replace the "Position" and "Bounds" properties. The Top and Left values come right out of the "MastRect" cluster, then you will have to calculate the Height and Width values using the "MastRect" Bottom and Right values.

Mouse Down Array 2.png

Active Participant Eric1977
Active Participant

You do not need to wire anything to the count terminal for the For Loop since your already auto-indexing. Just delete it.

Active Participant JimChretz
Active Participant

I think it's relevant to point out we can get the reference for the array element and get some of its properties including the value, not the index though... I guess we can't get the references array because the number of elements will change in run-time.

I think I can't attach the VI file but here's the block diagram.2015-06-11 14_04_44-getArray_clicked_value.vi Block Diagram.png

Trusted Enthusiast
Trusted Enthusiast

Here is a less complicated version:

WhichArrayElementClickedOn.PNG

It accounts for the possibility of the array being scrolled away from 0,0, and disregards any labels that may be showing.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Member carlos_camargo
Member

CoastalMaineBird's answer was a perfect solution for the problem I had.  I just modified it to work for a 1-D array and to work from references so I could have it as a subVI.  I'd Kudo's him if I could but his message somehow doesn't allow itself to be kudo'd.

1-D_Select.png

Member Schliepe
Member

Thanks top carlos_camargo for posting this nice solution.  I took that and updated it to do it for a 2D array.  I hope this helps someone else.Find Index of 2D Array.png