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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get key focus from control array Mouse Up event

Solved!
Go to solution

I have a <Controls[]>:Mouse Up event in which I need to determine which control was clicked on.  Attached is simplified example of my code that drills down into the Controls array to find which has the Focus. In use, I am trying to identify which control was clicked on the front panel of a vi that is inside a subpanel. The example I show uses a cluster because it exemplifies my point a little better since it involves another level of 'drill down' vs a simple (native) front panel control.

 

Get CtlRef with Focus from Cluster.png


There a number of forum threads regarding catching events from VIs loaded into subpanels, some of which involve creating a user event in the subvi that would be captured in the calling vi. Is there a more direct and/or elegant way to accomplish what I have shown WITHOUT the use of a user event inside of the embedded vi?

The reason for avoiding the user event approach is that there are numerous vis that can  be loaded into the subpanels and 1) I don't want to modify numerous vis and 2) I want to keep those vis simple.  

0 Kudos
Message 1 of 8
(3,970 Views)

You can use Dynamic Events.

 

After opening the VI to be placed in the sub-panel find the controls you are interested in the FP and get refs for the ones you want.

 

Use those refs to register for events.

 

When you switch out the VI in the sub-panel re-register for the controls on the new inserted VI.

 

Lather rinse repeat...

 

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 8
(3,939 Views)

Thanks Ben. I will have many different sub VIs that will be loaded. They will all be fairly simple but I do not know how many controls there will be in advance. Some may have 1, 2 or 3 native controls, some may be string, some numeric, some in a cluster and some individual. So wouldn't that mean that I would need to create an array of the refs I'm interested in... in which case wouldn't I end up with the same situation I have now, which is having get the Controls[] array and parse into it?

 

 

0 Kudos
Message 3 of 8
(3,931 Views)

Also, I am openiing the VI references with the 0X100 parameter, Prepare to Call and Collect followed by a Start Asynchronous Call... I think this means I " No access to outputs of the target VI". So how would I get the refs out? This is why I ended up Dynamically registering the Mouse Up event.

0 Kudos
Message 4 of 8
(3,926 Views)

I have to run today so I can not dwell to answer.

 

I was only trying to answer your question and made no comment of the wisdom of that approach. I do not like it because it adds dependencies between the GUI and the inserted objects.

 

can you switch over to a "tend to thy self" approach to decouple the GUI and sub-panels?

 

I would think only those operations that are common to all plug-ins would be implemented in the GUI and the unique operations assigned to the sub-panel VIs.

 

Take care,

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 8
(3,893 Views)
Solution
Accepted by topic author NI-hilator

kf.png

"If you weren't supposed to push it, it wouldn't be a button."
Message 6 of 8
(3,889 Views)

Thanks Paul!   This is awesome. It will make the code a little simpler. I tested with individual Numeric and String controls as well as Numeric and/or String controls within a cluster (native or TypeDef) and this works great. However, it does not seem to work with Arrays of controls of either Numeric or String. When I click on a control within a control array, the FindCtrlWithKeyFocus returns Not A Refnum and CtrlFound=false.  I vaguely recall reading something about this being a know issue? And various workarounds for using the control size, location of mouse when click and some simple math determine which element in the control array was click. In my case, non or my existing VIs that will go into the subpanel have a control array, and if I need one in the future, I'll just use a cluster instead.

 

For readers, I want to note something that may not be obvious: the FindCtrlWithKeyFocus method only returns control refs and true for numeric and string controls, other controls like boolean, and enums  will not. I have not tested with combo boxes or tables etc.

0 Kudos
Message 7 of 8
(3,884 Views)

Hi, I was ok with the invoke node FindCtrlWithKeyFocus, until I have to use an Array, well after some search an testing I finally diceded to go control by control reference.

Usig a rentrant subVI, the code gets more clean and you can add more ClassName Controls to the case selector.

At the moment you can get the key focus in Array, Cluster, Tabs nested.

 
 

imagen.pngimagen.pngimagen.pngimagen.pngimagen.png

0 Kudos
Message 8 of 8
(2,400 Views)