04-24-2011 03:05 PM
Hi all,
In many of the programs I've written it seems to come up that I want to programmatically enable/disable/hide a group of controls based on user input. In the past I've often ended up initializing an array of references to the controls for each group at the beginning of my code and then passing these arrays into a for loop whenever I needed the controls changed.
This method seems messy to me and I was wondering if anyone had a suggestion of a better way to go about this.
Thanks in advance.
04-24-2011 07:08 PM
That's the way I would do it. If needed, you could do some of this in a subVI so that you can hide some of the activity. Create an Action Engine that builds the array of refernces and stores them. Then when needed, call the action engine to enable or disable your array of controls.
The only other possibility would be if a group of controls are inherently related that they should be a part of a cluster, in which case you just enable/disable the cluster.
04-24-2011 08:25 PM
One other method is to pass an array of strings town to a subvi that will find a pane.controls[] by the lable.text then disable or enable the control, this is less coding but is more error prone since changing a control label requires updating the strinmgfs in the program.
I have used both over the years.
04-24-2011 11:22 PM
04-25-2011 03:32 AM
I use the same method as mentioned by "falkpl". It works great with me but the only problem with the deletion of FP controls/indicators. To prevent conflicts due to control names changes i search and disable them based on the caption names
04-25-2011 07:44 AM
When I make a GUI, I usually create a cluster of strict references for all the visible front panel objects. I make this a typedef (so it can be easily modified) and use it as input to subVIs which enable/disable/move/resize controls. It is the subVIs which define the behavior.
Note that using control references is the slowest way to set values, so is not recommended.
04-25-2011 09:29 AM
One other really cool method I have recently been exploring that use scripting (YES THIS IS ALLOWED IN 2010!)
is using the tag method. Every control has a metadata section called tags which is essentially a string,variant pair for adding all sorts of information to your control. This is a method of all controls so it can be used in a generic manor. You can use this to define groups of behaviors for all controls. There is some setup required for this but does open the possibility of doing some neat generic property setting.
When I have used this more (and have the time) I will try to post a nugget on it.
If this was exposed on the properties page it would be very cool (but it is not).
04-25-2011 10:13 AM
A very fast and easy way to disable/enable multiple controls on a FP is to use an invisible (as in colored using all transparent colors) string control that is disabled. If your controls are all located in the same region of the FP place them under this invisible control. Simply hide or show this control to enable/disable all everything that is under it. If you do use this approach make sure to document it on the block diagram. This definitely is not as elegant as some of the proposed suggestions but it works quite effectively.
04-25-2011 01:26 PM
Here are two utilities which make it very easy to create both the array of references and the cluster of references:
https://decibel.ni.com/content/docs/DOC-5678
https://decibel.ni.com/content/docs/DOC-5813
04-25-2011 01:56 PM
@Ravens Fan wrote:
That's the way I would do it. If needed, you could do some of this in a subVI so that you can hide some of the activity. Create an Action Engine that builds the array of refernces and stores them. Then when needed, call the action engine to enable or disable your array of controls.
The only other possibility would be if a group of controls are inherently related that they should be a part of a cluster, in which case you just enable/disable the cluster.
There is more than 1 school of thought on the subject. I tend to use Raven's Fans approach an create an AE for groups of FP Objects and let the AE mainage the referances and act on the control's "Visable" and / or "enabled" properties. You can do this a number of ways by either calling the AE when things change and you want to change whats showing on th GUI or you might even register an event so the AE can just do its thing when things change.
Serendipity time!
Just this morning the same topic was being discussed in the Community Nugget Series: Application development- Installment 2 Where Ben and I are commenting on "Show Hide Controls.vi" that is a AE within the system for preforming this exact function.