mrpaully


Does anyone know how to get the string of every selected item in a listbox I seem to only get the last selected item and not the rest.

I have foxpro V9 SP1

Cheers...



Re: Retrieving values of every selected item in a listbox

Budoi


The ff code puts all the selected items into a single string:

Code Snippet

myString = ''
FOR Counter = 1 TO ThisForm.myListBox.ListCount
IF ThisForm.myListBox.Selected(Counter)
myString = myString + ' ' + ThisForm.myListBox.List(Counter)
ENDIF
ENDFOR







Re: Retrieving values of every selected item in a listbox

mrpaully

It keeps saying record is out of range





Re: Retrieving values of every selected item in a listbox

Budoi

How do you populate your listbox And what line does the "record out of range" error appear




Re: Retrieving values of every selected item in a listbox

mrpaully

Its loaded from a field in a table.

It fails on the

myString = myString + ' ' + ThisForm.myListBox.List(Counter)




Re: Retrieving values of every selected item in a listbox

MarciaAkins

mrpaully wrote:
Does anyone know how to get the string of every selected item in a listbox I seem to only get the last selected item and not the rest.

ListIndex points to the last item seleted in a muti-select listbox. This is how to get all the selections:

LOCAL lnItem, lcString

lcString = ''

*** build a string of selected items to display

WITH Thisform.MyListBox

FOR lnItem = 1 TO .ListCount

IF .aSelected[ lnItem ]

lcString = lcString + ( .List[ lnItem ] ) + CHR( 13 )

ENDIF

ENDFOR

ENDWITH

MESSAGEBOX( lcString, 64, 'Selected Items' )






Re: Retrieving values of every selected item in a listbox

Naomi Nosonovsky

How many columns do you have in your listbox See List property in Help
Code Snippet
Control.List(nRow [, nCol]])[ = cChar]

So, if you have more than one columns in your listbox you need to add the Column number in the code above.
Also the "record out of range" sounds like a different problem. 
It usually means exactly what it says, 
.e.g. somewhere in your code you're trying 
to go to a non-existing record in a table.