03-04-2021 08:33 PM
I've found the example for "Get Array Names from Cluster", which converts the cluster to an array of controls, but that doesn't give the names in order. (I'm trying to automatically get column names for a table). I can't find any property that says what the element's position is in the cluster.
Solved! Go to Solution.
03-04-2021 09:31 PM - edited 03-04-2021 09:33 PM
In your cluster property node, don't use AllObjs[] property. Use the Controls[] property. It will give you all control references in order.
03-04-2021 09:52 PM
@RavensFan wrote:
In your cluster property node, don't use AllObjs[] property. Use the Controls[] property. It will give you all control references in order.
Just out of curiosity,
mcduff
03-04-2021 10:18 PM
Thank you very much!
03-04-2021 10:21 PM
Basically because I've never worked with these properties before and I just cut-and-pasted from the example. Now that I know what I'm doing, I can pare it down.
03-05-2021 09:19 AM
@mcduff wrote:
@RavensFan wrote:
In your cluster property node, don't use AllObjs[] property. Use the Controls[] property. It will give you all control references in order.
Just out of curiosity,
- Why do you "typecast" (to a more specific reference) to a control? (It appears the reference is already a generic control reference.)
- Why not expand the first property node to contain both Class Name and Text Label? (I know that won't speed up anything, just make the diagram cleaner.)
- If you are closing references, why not index the controls output and close all of them instead of only the last one?
mcduff
All of those things you mentioned are remnants of the original code that the poster had sent. I just fixed the part that was broken about cluster order. I think the typecast made sense in his original code because the class was a GObj rather than a control. I'm not sure what the use of ClassName is for in his code.
As for the Close reference, you are definitely right that should be inside the For Loop. Though I think this is one of those cases where you don't need to worry about closing that reference at all.
03-05-2021 09:20 AM
Or you make it easy on yourself and use 2 Variant VIs. 🙂
03-07-2021 12:58 AM
@pblase42 wrote:
...but that doesn't give the names in order.
To be clear, "in order" is ambiguous. Looking at your cluster, you're probably expecting the elements to be sorted based on their Y position, but there is nothing in LV which does that. If you want to achieve that, you would have to get the reference, extract the Y property and sort the referenced based on that.
The Controls[] property is sorted by tabbing order (which in the case of a cluster set to auto-arrange vertically is the same as sorting by the Y position) and the AllObjs[] property is sorted by Z order (because the cluster can include elements which can't be tabbed to and are therefore not in the tabbing list). Note that both of those orders can be changed (the tabbing by changing the tabbing order and the Z order by moving objects forward or backward), which will change the result you're getting.