Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic search into a character field
Message
De
09/05/2001 15:30:52
 
 
À
09/05/2001 14:25:08
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00505454
Message ID:
00505500
Vues:
29
Hi Mario.

>> I need to get to CODE to make a dynamic search into a characters field.
For example, I have a text box where I expect to get the name of a person, company, brand, title, whaterver. What I want is : When the user inputs the first letter, down into a Grid or a Browse or Something appears those "person, company, brand, title" whose name start with that letter. <<

You mean youwant an incremental search text box? If this is the case, we have exactly the class you need in chapter 4 of "1001 Things You Wanted to Know About VFP" ( Akins, Kramek, Schummer - Henzenwerke Publishing).

I do not have the room or time to post all of the code that you need to do this, but basically, you need to trap the keystrokes and take action to search the specified alias. This method code, from a custom text box method called HandleKey, is called from the text box's KeyPress. It should help get you started if you are trying to write your own incremental search textbox:


LOCAL lcSofar, lnSelect, lnSelStart, lnSelLength
WITH This
*** Get the value typed in so far
lnSelStart = IIF( LASTKEY() # 127, .SelStart, .SelStart - 1 )
*** Handle and empty value in the text box
IF lnSelStart = 0
.Value = ''
.SelStart = 0
GO BOTTOM IN ( .cAlias )
SKIP IN ( .cAlias )
ELSE
lcSofar = LEFT( .Value, lnSelStart )
.Value = lcSoFar
*** Use seek to find the record if a tag was provided
IF ! EMPTY( .cTag )
IF SEEK( UPPER( lcSoFar ), .cAlias, .cTag )
.Value = EVAL( .cAlias + '.' + .cField )
ENDIF
ELSE
*** Otherwise, save the current work area before swithching to the specified table
lnSelect = SELECT()
SELECT ( .cAlias )
*** And locate the specified record
LOCATE FOR UPPER( ALLTRIM( EVAL (.cField ) ) ) = UPPER( lcSoFar )
IF FOUND()
.Value = EVAL( .cAlias + '.' + .cField )
ENDIF
SELECT ( lnSelect )
ENDIF
ENDIF
*** If we need to refresh the parent container (usually a form or a page, do it here
IF .lRefreshParent
.RefreshParent()
ENDIF
*** Highlight the portion of the value after the insertion point
.SelStart = lnSelStart
lnSelLength = LEN( .Value ) - lnSelStart
IF lnSelLength > 0
.SelLength = lnSelLength
ENDIF
*** If we have refreshed the controls in the parent container, there are timing issues to overcome
*** Even though .SelStart and .SelLength have the correct values at this point, the search box
*** does not appear highlighted correctly without this delay
=INKEY(.1)
ENDWITH

HTH

Marcia
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform