Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiselect Listbox
Message
 
 
To
21/01/2003 15:44:23
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00743914
Message ID:
00743949
Views:
10
>Hello all! I have just added a listbox to a form in my application and set the multiselect property to .T. The listbox is working fine, I am trying to figure out how to store the data the user selects so that I can use it as search criteria in a SQL statement. Can anyone shed some light on this for me?
>
>TIA!

Save them in configuration file (MetaFile) as comma -delimited list.

Here is some code from multi-select listbox class used for User's selection. Also take a look into Container based on Multiselect Grid class in Downloads section here. I've designed an application with several classes, which I use for creating User selection criteria and saving configuration.

===========================
********************************************************************
*  Description.......: BTCC_MultiList.BTC_ItemList: method to return a comma-delimited list of the selected items
*  Calling Samples...:
*  Parameter List....:
*  Created by........: MDA
*  Modified by.......: Nadya Nosonovsky 12/29/1999 04:20:21 PM
********************************************************************
* 11/26/99 NN added into this method an ability to populate btcselarray
* 12/14/99 NN added AllSelected property
* Returns a comma-delimited list of quoted codes corresponding to those selected.
* If none, returns the empty string.
local result, n, k, lnSel, lnLen
* check for empty array special case
if alen(this.btcValArray) <= 1			&& array is empty
	return ''							&& null list result
endif
result = ''								&& start with nothing
k=0
lnSel=0
with this
	lnLen=alen(.btcValArray, 1)
* loop over the array, building list of selected codes
	for n = 1 to m.lnLen				&& cycle over rows
		if .Container1.List1.selected(m.n)			&& this item is selected
			lnSel=m.lnSel+1 && increment count of selected items
			if m.k>=1 and ascan(.btcSelArray, .btcValArray[m.n,2])>0 && This code already exists
* Do nothing
			else
				result = m.result + iif(empty(m.result), '', ',') ;
					+ '"' + .btcValArray[m.n, 2] + '"'	&& tack on another code
				k=m.k+1
				dimension .btcSelArray[m.k] && redim array
				.btcSelArray[m.k]= .btcValArray[m.n,2]
			endif
		endif
	endfor
	.btcCrit=m.result && store in a property
	if lnSel=m.lnLen and not .ExcludeFlag && All selected and don't need to be excluded
		.AllSelected=.t.
		result='' && empty criterion
		.nSelects=0
	else
		.AllSelected=.f.
		.nSelects=m.lnSel
		if !empty(.TableName) && Need to insert records into the table
			select (.TableName)
			zap && clear previous result
			for k=1 to .nSelects
				insert into (.TableName) ;
					values (.btcSelArray[m.k]) && Populate table with selected items
			next
		endif
	endif
endwith
return m.result 	&& done - return list of selected codes
** Restore selections
********************************************************************
*  Description.......: BTCC_MultiList.BTC_ListSelect: method to select a comma-delimited list of codes
*  Calling Samples...:
*  Parameter List....: list_arg
*  Created by........: MDA
*  Modified by.......: Nadya Nosonovsky 01/14/2000 04:07:16 PM
********************************************************************
* 8/4/99: Adapted from preliminary logic for handling the Counties listbox.
* 12/14/99 NN changed the code to better handle lots of items selected (AT instead of INLI)
* This method is used for state-saving/restoration of the listbox.
*
* Note that the behavior of this method is additive, to allow for anticipated need to
* split up steps due to VFP's 256 character macro/expression length limit.
lparameters list_arg	&& takes 1 required arg
* list_arg:				list of codes, in a form suitable for arglist to inlist().
with this
	if alen(.btcValArray) <= 1		&& array is empty
		return							&& no-op
	endif
	if empty(m.list_arg)
		list_arg=.btcCrit
	endif
	local n, lnSel,  lnCodes, lnLen
* check for empty array special case
	lnLen=alen(.btcValArray, 1)
* loop over the array, checking each item against the given list
	for n = 1 to m.lnLen				&& cycle over rows
		if at(.btcValArray[m.n, 2], m.list_arg)>0     && this item is to be selected
			.Container1.List1.selected(m.n) = .t.	&& flag list item as Selected
		endif
	endfor
	if !empty(.TableName)
		lnSel=select() && save current area
		select (.TableName)
		if reccount()<1 and !empty(m.list_arg) && First time
			local array laCodes[1]
			lnCodes=aparser1(@laCodes, m.list_arg,',')
			for i=1 to m.lnCodes
				insert into (.TableName) values (laCodes[i])
			next
			if !empty(.InputClass)
				lObj=evaluate('this.container1.'+.InputClass+'1')
				lObj.requery()
			endif
		endif
		select (m.lnSel) && return to previous area
	endif
endwith
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform