The VALUES and VALUE properties
Published 04 OCT 2015 at 11:51:16PM
When working with ListBox and ComboBox controls it can sometimes be a chore to derive an "internal" value from list of visible items. In many cases this involves creating an associated array of internal values, storing them in the MISC property (or a custom "@" property), and then extracting this array and the SELPOS property at runtime to arrive at the required data.
For example:
// Set up a LIST and internal items colorNames = "Red" : @fm : "Green" : @fm : "Blue" colorVals = 0x0000FF : @fm : 0x00FF00 : @fm : 0xFF0000 call set_Property_Only( @window : ".LIST_1", "LIST", colorNames ) call set_Property_Only( @window : ".LIST_1", "MISC", colorVals ) ... // Then at runtime to access the currently selected internal value colorVals = get_Property( @window : ".LIST_1", "MISC" ) selPos = get_Property( @window : ".LIST_1", "SELPOS" ) colorVal = colorVals ... // Or even more long-winded, find an internal value from the external one: colorNames = get_Property( @window : ".LIST_1", "LIST" ) colorVals = get_Property( @window : ".LIST_1", "MISC" ) locate "Green" in colorNames using @fm setting pos then greenVal = colorVals end ... // or perhaps setting the currently selected item from an internal code: colorNames = get_Property( @window : ".LIST_1", "LIST" ) colorVals = get_Property( @window : ".LIST_1", "MISC" ) locate 0x00FF00 in colorVals using @fm setting pos then greenName = colorNames call set_Property_Only( @window : ".LIST_1", "TEXT", greenName ) end
To make this style of coding somewhat cleaner, OpenInsight 10 introduces the new VALUES property, which allows you to set an "internal" value for each item in the control, along with property indexing support. There is also a new VALUE property, which is the counterpart to the standard TEXT property, and provides access to the currently selected item via it's internal value.
Here's the above examples rewritten to use VALUES and VALUE instead:
// Set up a LIST and internal items colorNames = "Red" : @fm : "Green" : @fm : "Blue" colorVals = 0x0000FF : @fm : 0x00FF00 : @fm : 0xFF0000 call set_Property_Only( @window : ".LIST_1", "LIST", colorNames ) call set_Property_Only( @window : ".LIST_1", "VALUES", colorVals ) ... // Then at runtime to access the currently selected internal value colorVal = get_Property( @window : ".LIST_1", "VALUE" ) ... // Find an internal value from the external one: greenVal = get_Property( @window : ".LIST_1", "VALUES", "Green" ) // or by position greenVal = get_Property( @window : ".LIST_1", "VALUES", 2 ) ... // or perhaps setting the currently selected item from an internal code: call set_Property_Only( @window : ".LIST_1", "VALUE", 0x00FF00 )
VALUES and VALUE apply to both ListBox and ComboBox controls.
(Disclaimer: This article is based on preliminary information and may be subject to change in the final release version of OpenInsight 10).
Comments
At 05 OCT 2015 01:29AM Don Bakke wrote:
This certainly seems like a helpful improvement. Another way to avoid the cumbersome approach is to create a UDC that displays one value and returns another.
At 05 OCT 2015 01:11PM Craig Tildesley wrote:
I can't remember if you already said but is VALUE read only or can you set your listbox/combo using it?
At 05 OCT 2015 01:55PM Captain C wrote:
Hi Craig - you can use it to set the current selection if you wish - look at the last statement in the second code example to see how it's done.