Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combobox input
Message
De
22/03/2016 19:55:24
 
 
À
22/03/2016 15:57:03
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01633537
Message ID:
01633566
Vues:
76
*lazy i adapted this code from http://www.tek-tips.com/faqs.cfm?pid=184&fid=1792
* as Koen suggested.
*if you add a new value, valid and confirm if want to add to current cursor(readwrite).
publi yform
yform=newObject("asup")
yform.show
read events
retu

DEFINE CLASS asup AS form
	Top = 14
	Left = 144
	Height = 282
	Width = 496
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"

	ADD OBJECT combo1 AS combo_autofill  WITH ;
		Height = 49, ;
		Left = 24, ;
		Top = 24, ;
		Width = 217, ;
		Name = "Combo1"

	PROCEDURE Load
		sele company from home(1)+"samples\data\customer" into cursor ycurs readwrite
	ENDPROC
	
	Procedure destroy
	clea events
	endproc
ENDDEFINE


DEFINE CLASS combo_autofill AS combobox
	RowSourceType = 6
	RowSource = "ycurs.company"
	Height = 37
	Left = 36
	Top = 24
	Width = 205
	 acstyle  = 2
 lastdisplayvalue = ""
 lastsellength = 0
 lastselstart = 0
	Name = "Combo1"

	PROCEDURE Requery
		this.Value = this.DisplayValue 
	ENDPROC

	PROCEDURE InteractiveChange
		LOCAL lnStyle, lnLastKey, lcDisplayValue
		lnLastKey=lastkey()
		lnStyle = this.style
		IF this.style = 2
		    this.style = 0
		ENDI
		IF (lnLastKey>=32 and lnLastKey<=126)
		    IF this.selstart>=1
		        lcDisplayValue=substr(this.displayvalue,1,this.selstart-1)+(chr(lnLastKey))
		    ELSE
		        lcDisplayValue=(chr(lnLastKey))+allt(this.displayvalue)
		    ENDI
		    IF empty(lcDisplayValue)
		        lcDisplayValue=allt(chr(lnLastKey))
		    ENDI
		    FOR i = 1 to this.listcount
		            If Upper(lcDisplayValue) == Upper(Substr(This.List(i),1,Len(lcDisplayValue)))
		                This.DisplayValue=This.List(i)
		                This.SelStart=Len(lcDisplayValue)
		                nlLength=Len(Allt(This.DisplayValue))-Len(lcDisplayValue)
		                This.SelLength=Iif(nlLength <0,0,nlLength)
		                this.lastdisplayvalue = this.displayvalue
		                this.lastselstart = this.selstart
		                this.lastsellength = this.sellength
		                RETURN
		            ENDI
		    ENDFOR
		ENDIf
	ENDPROC

	PROCEDURE Valid
		If !Empty(This.DisplayValue)
		    Local cTableName,cFieldName,nAnswer,cValue
		    Store Juststem(This.RowSource) To cTableName &&Won't work for VFP5.0
		    Store Justext(This.RowSource) To cFieldName && This is normally used for 3 character extension, but it works for any lenght. Won't work for VFP5.0
		    Select (cTableName)
		    Locate For &cFieldName = This.DisplayValue
		    If !Found()
		        nAnswer = Messagebox("This value was not found in the table,"+Chr(13)+"Do you want to save it in the table?",36,"")
		        If nAnswer = 6
		            Insert Into &cTableName (&cFieldName) Values (This.DisplayValue)
		            If CursorGetProp("Buffering") > 1  && Check to see if we should use tableupdate
		                Tableupdate(1,.T.,cTableName)
		            ENDIF
		        this.Requery() && To reset the display value
		        Else
		            Store '' To This.DisplayValue
		        Endif
		    Endif
		ENDIF
	ENDPROC

ENDDEFINE
*
*-- EndDefine: combo_autofill
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform