LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

combobox in array--why does it work this way?

I have attached a snippet of a subVI I'm using to initialize the items and set the values of comboboxes in an array. I modified it slightly so the array being referenced is on this block diagram, not a top level diagram. It took me a while to come to this solution; before I had the combobox part in a for loop and was trying to loop through each array element, get a reference to that element, and set the strings[] and value properties but it was acting all wacky. Then I changed it to the way below and it automatically populates all the comboboxes with the correct values, and then sets their values each to be different (which is what I want!) My question is, why does it work this way? I understand all elements in an array need to be the same (although I did find a work around here.), but the part about setting the values to each be different I was trying to do manually with a property node and a value property, when I realized the combobox just handles it all itself. Is this just a feature of a combobox in an array I need to note for future reference? 

 

edit: I noticed the testers array reference label changed, so hopefully it's still referencing the same control. You may need to relink it.

 

 

 

0 Kudos
Message 1 of 20
(3,874 Views)

To make sure I'm understanding your question: are you asking why you can set the value for the entire array at once, but not set the value of an individual element in it?

 

You cannot get a reference to an individual element in an array control.  The ArrayElem reference will always refer to the same control regardless of what array index is visible.  This isn't specific to a combo-box, every array works like this.

0 Kudos
Message 2 of 20
(3,867 Views)

@nathand wrote:

To make sure I'm understanding your question: are you asking why you can set the value for the entire array at once, but not set the value of an individual element in it?

 

You cannot get a reference to an individual element in an array control.  The ArrayElem reference will always refer to the same control regardless of what array index is visible.  This isn't specific to a combo-box, every array works like this.


 

I have not tested it lately but as of the time of this Nugget I found that it will point to the top left visable array element.

 

This image

 

 

from the "How to Index the Array" section just barely shows the arry index being manipulated.

 

The code is included in that Nugget if you want to see it for yourself. I can not speak to the fact if it still works in  modern versions of LV.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 20
(3,857 Views)

@Ben wrote:

@nathand wrote:

You cannot get a reference to an individual element in an array control.  The ArrayElem reference will always refer to the same control regardless of what array index is visible.  This isn't specific to a combo-box, every array works like this.


I have not tested it lately but as of the time of this Nugget I found that it will point to the top left visable array element.


The ArrayElem property always returns the same reference no matter which element of the array is in the top-left corner, as demonstrated by the code below (screenshot instead of snippet to avoid mangled references and property nodes).

all array elem refs same diagram.PNGall array elem refs same panel.PNG

Message 4 of 20
(3,849 Views)

@nathand wrote:

@Ben wrote:

@nathand wrote:

You cannot get a reference to an individual element in an array control.  The ArrayElem reference will always refer to the same control regardless of what array index is visible.  This isn't specific to a combo-box, every array works like this.


I have not tested it lately but as of the time of this Nugget I found that it will point to the top left visable array element.


The ArrayElem property always returns the same reference no matter which element of the array is in the top-left corner, as demonstrated by the code below (screenshot instead of snippet to avoid mangled references and property nodes).

all array elem refs same diagram.PNGall array elem refs same panel.PNG


 

 

 

 

 

 

 

 

 

Yes that is true but the value returned when using a property node >>> value will return the top left displayed value. In the code included in that Nugget, I set the size of the control such that it only shows a single element then by manipulating the index control I can raed each element in the array.

 

At least that is how it behaved back in the day of that nugget.

 

Yes, my wife left me home alone with a case of beer and LV to find that tidbit. I suspect that feature will one day disapear without anyone noticing.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 20
(3,843 Views)

Just to illustrate Ben's point...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 20
(3,834 Views)

Initially I was trying to loop through the indices of the array by first changing the "index val" to 0,1,2...n, then getting the array element reference to try and get the references to the individual controls within the array. That's when I realized I was having all sorts of issues and this wasn't how references to individual elements in an array worked.

0 Kudos
Message 7 of 20
(3,828 Views)

Now I'm SUPER confused. I originally had it how crossrulz shows (or so I thought I did) and it was acting really strange. That's what prompted me to ask the question I just set it back to be the way I had thought I had it, and I can't reproduce the problem! I wonder if a wire was hiding or I had some referenced wired up wrong and didn't realize it. Ugh, I wish I had just diagram disabled.

0 Kudos
Message 8 of 20
(3,825 Views)

Just so I can pummel this thread and keep it at the top of the list today, I realized what's going on. The screenshot below shows how I had it before. Basically, when I wire an empty array for the "value" up to the array first, it's not fully clearing the array if some combobox elements are still hanging around. Why isn't this emptying the array? See the attached VI if you want code that reproduced the problem.

 

Download All
Message 9 of 20
(3,819 Views)

I think all I can do at this point is encorage you "Go Greg, Go Greg Go!" and point out I never attempted to mess with a combo box so you maybe discvering a new behaviour never seen or reported previously.

 

If you figure it out, please let us know what you find.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 20
(3,805 Views)