LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can we populate a combo box dynamically?

I know we can type in the items to be selected statically, but I'm trying to do it dynamically. I tried but still couldn't figure out how to do it. Any one can give some help? Other kind of pull-down boxes are also ok. Thanks in advance.
 
Guangde
0 Kudos
Message 1 of 19
(7,755 Views)
I don't think you can do this programmatically.  You are basically trying to modify the control itself, and this is not possible while the VI is running.  Modifying the items in the list is like replacing it with a completely different control.  If it were possible, you would be able to change it using a property node.  I tried this just to see what happens.  It tells me that it is not possible to change this property while the VI is in run mode.  Thus, the control cannot be modified while the VI is running.  That being said, there may be another way out there that I don't know of.  The problem is that with something like an enum control, you have individual strings associated with integers.  Modifying the strings changes the relationship and thus the structure of the control itself.
0 Kudos
Message 2 of 19
(7,750 Views)
Thank you for your response. It's possible that it can not be done, but I still need to figure out a way to do it. Maybe you can give some suggestions about how to achieve this. I have a table of items, I need to read then in and select one of them. How we can make it if we can not use the combo box?
0 Kudos
Message 3 of 19
(7,745 Views)
What are you reading in?  Strings?  What condition are you using to select one of them?  You could put them in an array, so that each entry is indexed.  If you needed to find a particular string you could search for it in the array and return the corresponding index maybe.  Or if you needed a particular string you could reference it by index.  A little more info about what you're doing would help, though.  Can you maybe post a VI?
Message 4 of 19
(7,739 Views)
Thank you for your response. The items are strings which are pre-entered into a table and we need to read then in and select one of them manually. It's a database application. I don't have the VI yet, I'm just trying to see how we can make it work. I can make the items into an array, but afterwards, how can we list them and select one of then?
 
Best regards,
 
Guangde
0 Kudos
Message 5 of 19
(7,734 Views)
Well, you could display the array of strings just using an array indicator (you can right-click the wire carrying the array and select Create-->Indicator to create it quickly).  Then, create a numeric control to let the user select the index of the appropriate string.  In your code, you could then just pull out that array element and use it for whatever you need it for.
Message 6 of 19
(7,729 Views)

It may be a way to do it. I'll try it then I'll let you know whether it works or not. Thank you very much for your help.

Guangde

0 Kudos
Message 7 of 19
(7,723 Views)
Yes, you can populate a combo box dynamically.  Take a look at the VI I have attached.
S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
Message 8 of 19
(7,721 Views)
How about using a text ring control? You use your array of string to populate the control's strings[] property. To get the string that was selected, use the ring value to index into the array of strings that you used to populate the strings[] property.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 9 of 19
(7,709 Views)
Thank you for the example, it works just like what I wanted. Guangde
0 Kudos
Message 10 of 19
(7,689 Views)