Jump to content


Photo
- - - - -

Multi Selection in a ListBox


2 replies to this topic

#1 Ivan Gomez

Ivan Gomez

    Member

  • Members
  • PipPip
  • 20 posts

Posted 16 May 2007 - 10:19 AM

Hello to everybody...

I need allow multiple selection in a ListBox. I have seen in the Single Developer demo that you can do it, but I don't find any property relative to it... Can anyone help me????


Thanks in Advance...

#2 jcduym

jcduym

    Member

  • Members
  • PipPip
  • 35 posts

Posted 22 May 2007 - 08:55 AM

Hi Ivan,

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.

Hth.


Jan

#3 DARREN

DARREN

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 396 posts
  • Gender:Male
  • Location:Florida,USA

Posted 22 May 2007 - 04:21 PM

Hi Ivan,

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.

Hth.


Jan


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
FLD("MyListbox")
ELSE
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
//
ENDFOR
ENDIF
ENDIF

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
Things should be made as simple as possible, but not simpler



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users