Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiselect list boxes

Status
Not open for further replies.

rclarke

Technical User
May 14, 2001
78
GB
Hello

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?

Thanks in advance

Rachel
 
Hi!

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.

Hope this helps.


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
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
------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top