Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combobox woes
Message
De
07/10/2008 09:21:59
 
 
À
05/10/2008 08:32:13
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01352729
Message ID:
01353254
Vues:
25
Marcia --

Thank you very much for your quickfill combobox, which my users are very appreciative of.

I've made two changes to your code:

(1) Your code had Returns within With / EndWith blocks. I corrected this.

(2) When you encountered a case where the user's text did not match any entries, you threw away all of the previous text entered. Instead, I just ignored the keystroke altogether, leaving the user's previous text intact
Proc HandleKey
Lparameters tnKeyCode
Local lcSofar, lnSelStart, lnSelLength, lnSelect, lcFld, lbNoDefault

*** Handle backspace key
If tnKeyCode = 127
	If This.SelStart = 0
		Return .F.
	Endif
	This.SelStart = This.SelStart - 1
	lnSelStart = This.SelStart
	lcSofar =  Upper( Left( This.DisplayValue, lnSelStart ) )
Else
	*** Get the value typed in so far
	lnSelStart = This.SelStart+1
	lcSofar =  Upper( Left( This.DisplayValue, This.SelStart ) + Chr( tnKeyCode ) )
Endif

*** See if we can find a match in the Alias used as the RowSource
lcFld = This.calias + '.' + This.ckeyfield
If  Not Empty( This.ctag )
	If Seek( lcSofar, This.calias, This.ctag )
		This.DisplayValue = Eval( lcFld )
	Else
		****************************************************************
		Return Not This.lallowaddnew
		*!*			If Not This.lallowaddnew
		*!*				This.ListIndex = 0
		*!*				lnSelStart = 0
		*!*			Else
		*!*				Return .F.
		*!*			Endif
	Endif
Else
	lnSelect = Select()
	Select ( This.calias )
	Locate For Upper( &lcFld ) = lcSofar
	If Found()
		This.DisplayValue = Eval( lcFld )
	Else
		****************************************************************
		Return Not This.lallowaddnew
		*!*			If Not This.lallowaddnew
		*!*				This.ListIndex = 0
		*!*				lnSelStart = 0
		*!*			Else
		*!*				Return .F.
		*!*			Endif
	Endif
	Select ( lnSelect )
Endif

*** Highlight the portion of the value after the insertion point
This.SelStart = lnSelStart
lnSelLength = Len( Alltrim( This.DisplayValue ) ) - lnSelStart
If lnSelLength > 0
	This.SelLength =  lnSelLength
Endif

EndProc
Thanks,

Jim
Jim Nelson
Newbury Park, CA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform