LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Listbox persistent items

Solved!
Go to solution

Hallo, I'm experiencing a strange behaviour of a Listbox. I populate the lb programatically with this code:

michelesantucci_1-1742293199662.png

 

michelesantucci_0-1742292868299.png

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

 

0 Kudos
Message 1 of 5
(203 Views)

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.

Message 2 of 5
(195 Views)
Solution
Accepted by topic author michele.santucci

@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.

0 Kudos
Message 3 of 5
(152 Views)

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.

 

  • A table is typically an indicator (despite LabVIEW insisting calling it a "table control", so vote for this!!!! )
  • A listbox is typically a control where the user can pick an item.

 

I sometimes substitute a listbox (as indicator!) for a table, but not the other way around....

0 Kudos
Message 4 of 5
(119 Views)

@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.

0 Kudos
Message 5 of 5
(108 Views)