03-18-2025 05:24 AM
Hallo, I'm experiencing a strange behaviour of a Listbox. I populate the lb programatically with this code:
It looks like once populated the items are stored between runs.
If I delete each rows and then save the "Current values as default" the list is empty stays empty just for the next run until is
populated then again it stores the values and keeps showing them all the times.
I don't think this behaviour is correct.. is it? How can I prevent it?
Best regards,
Mike
Solved! Go to Solution.
03-18-2025 05:40 AM - edited 03-18-2025 05:46 AM
Hi Mike,
This may be unintuitive, but it is expected.
The value of a Listbox is not the displayed items themselves, but rather an integer (or an array of integers) representing the index of the currently selected item(s). So when you do a "Reinitialize to Default", it simply resets which item(s) is/are selected, not the item names.
ItemNames being a property, it is persistent when you save the VI.
What you can do it write an empty array to ItemNames to clear the Listbox.
Regards,
Raphaël.
03-18-2025 07:52 AM
@raphschru wrote:What you can do it write an empty array to ItemNames to clear the Listbox.
That's a perfectly valid solution.
You can also use a table. A table's datatype is a 2D array of strings. So setting the value won't make them persist, unless you make them default.
03-18-2025 10:25 AM
wiebe@CARYA wrote:
You can also use a table. A table's datatype is a 2D array of strings. So setting the value won't make them persist, unless you make them default.
Typically, the use case for table vs. listbox is very different.
I sometimes substitute a listbox (as indicator!) for a table, but not the other way around....
03-18-2025 10:56 AM
@altenbach wrote:
wiebe@CARYA wrote:
You can also use a table. A table's datatype is a 2D array of strings. So setting the value won't make them persist, unless you make them default.Typically, the use case for table vs. listbox is very different.
I agree; I typed that remark a few times, but decided to remove it...
In OP's example, the only obvious use case is to display a 2D array of strings.
Table vs listbox is a pickle, each having their own use cases and esp downsides.