LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting ComboBox option strings programmatically in array of clusters

Solved!
Go to solution

I have an array of clusters where each cluster contains two combo boxes. When one string is selected in the first combo box, I want to update the available option strings in the second. For example, if you selected "Apple" in the first combo box, your possible choices for the second combo box would be: Gala, Fuji, Red, etc.

 

My problem is that I cannot seem to update the "Strings[]" property of the ComboBox inside an array element. I have figured out how to successfully write a value, but the Strings[] property does not seem to get changed correctly. I can write both value and Strings[] for a SINGLE cluster, but when I put them into an array it does not work. I tried putting the code into a flat sequence to make sure that the value and Strings[] on the new cluster are written first before replacing the cluster into the array.

 

My strategy thus far is to build up a new cluster and set the Value and Strings[] properties using the Controls[] array and then indexing each ComboBox to write a new value and list of string choices. Next, I replace the cluster (array element) that changed using the "In-Place Element Structure" and then finally write that result into a local variable for my array.

 

It is important that my original array of controls on the front panel be updated, not a "new" array or copy, thus I am unable to figure out a simpler way to do this using Dataflow programming. I had previously experimented with using the Replace Array Element block, but since the output of that is a new array, that will not work for me (unless I write it into a local variable as I have done with the in-place element structure).

 

I have shown an image below where my "New Element" is the cluster that will replace one of the clusters in the array. It shows that the "Hello" and "Goodbye" string values were transferred successfully to the new array. However, the option strings for the New Element are A,B,C and this is not being transferred to the new cluster element inside the array, as shown in the second picture where the option strings are seen to be x,y,z. I have attached a simple example VI as well.

 

Thanks for any help or suggestions.

 

Jason_Mandala_0-1594161690696.png

 

 

Jason_Mandala_1-1594161748604.png

 

Jason_Mandala_2-1594162031594.png

 

 

0 Kudos
Message 1 of 3
(2,400 Views)
Solution
Accepted by topic author A_Serious_Man

The current Value isn't part of the datatype for the Array Element (i.e. the cluster), so you can change it however you like (e.g. with In-Place Element Structure, or Replace Array Subset), but the Strings[] property is I believe part of the type of a Combo Box.

 

Since all elements of an array must be of the same type, you can't have an array of clusters in which the elements have 'different types'.

 

Some possible workarounds might include:

  • Instead of an array of clusters, consider a cluster of clusters. This is unpleasantly clunky, because if your number of values is more than a few, you'd need a scroll bar, and then you'd need to update which 'elements' were visible in your combined cluster of clusters control... However, it should work
  • Much nicer (sort of): Adjust the "Strings[]" property as you click the dropdown using an Event Structure. Several previous discussions have described this process, see links herehere, and most usefully (with nice demo solution) here: Edit a array of Cluster element property)

In the latter case, the Filter Event (with question mark in the event name) is used to trigger an Event on the Mouse Down over the array.

Then, the Strings[] property is rewritten.

 

This actually updates the Strings[] property for all of your elements in the array (not just the one you clicked) but since you only see the dropdown for the one you clicked, and the values don't change, it doesn't matter (at least in general, perhaps you care).

 

Spoiler
Above I wrote that it changes the properties for all of the elements - it's described in I think the first link above that in 'reality' there is only one "element" of the array, with a single set of properties, but that it has an array of Values. So really you're changing the properties of the (only) Array Element, and all of the array of Values are unchanged.

GCentral
Message 2 of 3
(2,368 Views)

Thanks for the tip and links.

 

The fact you were able to produce so many links is evidence of poor research or improper search terms on my part. I read some other threads not specific to combo boxes that said the same about all elements of the array having the same properties. I guess my trouble was not identifying that Strings[] is a property as opposed to a value of sorts. 

 

I understand the nuances of the clever solution provided. You are only viewing one combo box, but all of the Strings[] properties have changed for all elements. However, you wouldn't know until you clicked on one, which would change the properties for all again. Yes, in my application I'm really only concerned about storing the value, the Strings[] property is just for convenience to the user. So, that would work nicely.

 

Thanks again.

Message 3 of 3
(2,354 Views)