Multi Selection in a ListBox
Posted 22 May 2007 - 04:21 PM
The trick is to use an array as the variable in the listbox that receives the selected key(s). Best use the maximum size for an arry (250 elements) as you need as many elements as you have records in the listbox.
To elaborate on Jan's explanation, you must define and employ a variable (usually scratch variable) that is a dimensioned array. The array size should be set to the maximum number of multiple selections that you wish to permit. This variable name is then defined as the data source in the listbox control WITHOUT the subscript e.g. $MY_SELECTION_ARRAY(). This is one of the few instances where you can reference a variable in PROIV without a subscript.
There are then two possible ways you can action the selection(s). The first is simply in the loss of focus logic. Ensure that you test for carriage return (enter) when peforming the test i.e.
IF @FNKEY = 0 THEN // test for the enter key
IF $MY_SELECTION_ARRAY(1) = '' THEN
MSG(1) // Output an error as the user has not selected anything
FOR #COUNTER = 1 TO #MAX_ARRAY_SIZE // loop through the array and process the selections
$MY_KEY_VALUE = $MY_SELECTION_ARRAY(#COUNTER)
// my processing code goes here
This code could also be used in the event logic on a function key assigned to a button/icon. The test for @FNKEY of 0 would not be required as the function key is known.
It should be noted that each line selected populates the next available array element automatically. i.e. if lines 3,6 and 18 are selected from the list box, this will populate array elements 1,2 and 3 respectivley.
hope this helps
Reply to this topic
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users