Could anybody tell me if I have multiselect enabled on a list box how to save those items selected into a field in a table so that they may be veiwed again at a later date?
Let we have a listbox on the form called 'ListBox1'. It contains 2 columns, 1 is item description, another is item id (it could be a single column if ID is an item), second column is hidden.
Scan all items and prepare selections string:
lcSelected=''
for i=1 to thisform.ListBox1.ListCount
if thisform.ListBox1.Selected(i)
lcSelected = lcSelected + allt(upper(thisform.ListBox1.LIST[i,2])) + ','
endif
endfor
Than save the content of the lcSelected variable into the memo field (or character field if you're sure it is not longer than 255 chars).
Than, in refresh of the listbox, you can do following:
&& assume lcSelected is a variable that contains list of ID values of selected items
lcSelected = ','+lcSelected
for i=1 to thisform.ListBox1.ListCount
if ','+allt(upper(thisform.ListBox1.LIST[i,2]))+',' $ lcSelected
thisform.ListBox1.Selected(i) =.T.
endif
endfor
You can, of course, make a separate table which contain ID of selected item in each record (I usually d that way because it is more useful for SELECT queries). In such case instead of collecting values in the string you will add new record in that table for each selected item. Before that, of course, delete records fro previous selection. Whe reading, just scan these records, find appropriate item in list of listbox and mark it as selected.
Hi there,
If you want to store those items in a single field you can run something like this.
------------------------
WITH THISFORM
myString=''
For i=1 To .myList.Listcount
If .myList.Selected(i)
myString = myString + ';' + .myList.List(i)
EndIf
EndFor
myString=substring(myString,2)
** Insert this myString Value into your desired field
ENDWITH
------------------------
And when you are retrieving back the results you can do something like this.
------------------------
myString=ALLT(myString)+' '
i=AT(';',myString)
DO WHILE i<>0
THISFORM.myList.AddItem(SUBSTR(myString,1,i-1))
myString=SUBSTR(myString,i+1)
i=AT(';',myString)
ENDDO
------------------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.