Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP6SP5 - A TextBox which acts like a QuickFillComboBox
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00801073
Message ID:
00801099
Views:
21
This message has been marked as the solution to the initial question of the thread.
Is it possible to have a TextBox which works like a QuickFill ComboBox.

Add the following properties to your textbox class:

cAlias: name of alias to search in
cTag: Name of index tag to use
cField: Name of field to search on

This code in the 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
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	
ENDWITH
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform