Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Autofill textbox from my table
Message
De
02/06/2006 06:45:23
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01125959
Message ID:
01126700
Vues:
25
This message has been marked as the solution to the initial question of the thread.
i want fill my text box form table.

Create a custom text box class. Add custom properties cAlias, cTag, cField.

Fill this properties in ( in the instance ) with the name of the alias to search, the tag to use (if there is one) and the name of the filed to search on.

This code in KeyPress:
*** If the key pressed was a printable character or a backspace, handle the keystoke and search
IF ( LASTKEY() > 31 AND LASTKEY() < 128 ) OR ( LASTKEY() = 7 )
  IF This.HandleKey( nKeyCode )
    NODEFAULT
  ENDIF
ENDIF
Add a custom method called handleKey. This code in HandleKey():
LPARAMETERS tnKeyCode
LOCAL lcSofar, lnSelect, lnSelStart, lnSelLength

WITH THIS
  *** Get the value typed in so far
  lnSelStart = IIF( tnKeyCode # 127, .SELSTART + 1, .SELSTART - 1 )

  *** On backspace, remove one character from current position
  *** and search
  IF tnKeyCode = 127
    IF lnSelStart <= 0
      GO BOTTOM IN ( .calias )
      SKIP IN ( .calias )
      .VALUE = ''
      RETURN
    ELSE
      lcSofar = LEFT( .VALUE, lnSelStart )
    ENDIF
  ELSE
    *** Get the value typed in so far
    *** and add the current key stroke
    lcSofar =  LEFT( .VALUE, .SELSTART ) + CHR( tnKeyCode )
  ENDIF

  .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
  *** Highlight the portion of the value after the insertion point
  .SELSTART = lnSelStart
  lnSelLength = LEN( .VALUE ) - lnSelStart
  IF lnSelLength > 0
    .SELLENGTH =  lnSelLength
  ENDIF
  DOEVENTS
ENDWITH
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform