From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

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

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

 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.**



Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
ANCO_Engineers
Member
Member
on

Thank you for sharing...works great!

M.S.
fmlmf
Member
Member
on

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

Eric1977
Active Participant
Active Participant
on

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

JimChretz
Active Participant
Active Participant
on

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

CoastalMaineBird
Trusted Enthusiast
Trusted Enthusiast
on

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

carlos_camargo
Member
Member
on

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

Schliepe
Member
Member
on

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