Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What is the deal with Combos?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00273965
Message ID:
00273974
Vues:
22
>The problem is, if the current data was not in the list, the combobox value is blanked instead of setting its value to the data value from the ControlSource. What are the tricks to keeping and saving data values that are not part of the combo's list?
>
>TIA!

Hi Mark,

You probably just need to make sure .DisplayValue, .Value, and .controlsource all match. Here is the code for the cbo class I use. Look at the refresh method.

Note: The SQL select is in the requery event, I store the array in a property of the combo .aList, it populates itself from a table that contains keyed lookup values.
**************************************************
*-- Class:        cbosimplelookup (c:\my working files\workman\libs\fk_ui.vcx)
*-- ParentClass:  cbobase (c:\my working files\workman\libs\fk_base.vcx)
*-- BaseClass:    combobox
*-- Time Stamp:   09/09/99 11:43:01 AM
*
DEFINE CLASS cbosimplelookup AS cbobase


	RowSourceType = 5
	RowSource = "This.aList"
	Style = 2
	*-- Specifies which key is used to show items in the list
	lookupkey = "NoKeySet"
	Name = "cbosimplelookup"


	PROCEDURE Refresh
		DODEFAULT()

		LOCAL liOldValue, lnResult
		liOldValue = proper(this.displayvalue)
		lnResult = 1

		** When this is refreshed, check and make sure the display value is in the array
		IF !EMPTY(THIS.DISPLAYVALUE)
			lnResult = ASCAN(THIS.aList, THIS.DISPLAYVALUE)
		ENDIF

		IF lnResult = 0
			** Field value is not in list so add it.
			nNewListLen = ALEN(THIS.aList) + 1
			DIMENSION THIS.aList[nNewListLen]
			THIS.aList[nNewListLen] = THIS.DISPLAYVALUE
			ASORT(THIS.aList)
			THIS.DISPLAYVALUE = liOldValue
			THIS.VALUE = liOldValue
		ENDIF
	ENDPROC


	PROCEDURE Init
		LOCAL lnResult

		DODEFAULT()
		THIS.REQUERY()

		** If the field value is not in the combo list it
		** has to be added manually
		IF !EMPTY(THIS.CONTROLSOURCE)
			lnResult = ASCAN(THIS.aList, EVAL(THIS.CONTROLSOURCE))
		ELSE
			lnResult = 1
		ENDIF

		IF lnResult = 0
			** Field value is not in list so add it.
			aListLen = ALEN(THIS.aList)
			DIMENSION THIS.aList[aListLen + 1]
			THIS.aList[aListLen + 1] = EVAL(THIS.CONTROLSOURCE)
			ASORT(THIS.aList)
		ENDIF
	ENDPROC


	PROCEDURE Requery
		ASSERT (THIS.LookUpKey != 'NoKeySet') MESSAGE 'The lookup table key has not be set'

		lcSQLstr = "SELECT lkuValue " + ;
			"FROM lookUpTable " + ;
			"WHERE lkuKey LIKE '" + UPPER(THIS.LookUpKey) + "' " + ;
			"ORDER BY lkuValue"
		lcName = THIS.NAME + '1'
		THISFORM.oCon.SQLSelect(lcSQLstr, lcName)

		IF RECCOUNT() > 0
			DIMENSION THIS.alist[RECCOUNT(), 1]
			COPY TO ARRAY THIS.alist
		ELSE
			DIMENSION THIS.alist[1, 1]
			THIS.alist[1, 1] = ''
		ENDIF
		USE
	ENDPROC


ENDDEFINE
*
*-- EndDefine: cbosimplelookup
**************************************************
Roi
'MCP' Visual FoxPro

In Rome, there was a poem.
About a dog, who found two bone.
He lick the one, he lick the other.
He went pyscho, he drop dead!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform