Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grid Search
Message
De
12/02/2005 07:53:02
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
12/02/2005 07:48:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Versions des environnements
Visual FoxPro:
VFP 8
OS:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
00986211
Message ID:
00986260
Vues:
36
While I am sure you made it work, there is one thing which confuses me. Wouldn't the code to handle the keystrokes have to be invoked from each and every Column.TextBox.KeyPress? Wouldn't the KeyPress here have precedence over the Grid.KeyPress?

>You need to add a few couple of custom properties to your grid class and 2 custom methods: one called handlekey ( call handlekey from the grid's KeyPress to process each key stoke ) and one called Search, to perform the search in the grid's RecordSource. This code in HandleKey():
>
>
>LPARAMETERS tnKeyCode
>*** First check to see if we have a key that we can handle
>*** A 'printable' character, backspace or <DEL> are good candidates
>IF BETWEEN( tnKeyCode, 32, 128 ) OR tnKeyCode = 7
>  WITH This
>    *** First check to see if we have timed out
>    *** and reset the search string if we have
>    IF DATETIME() - .tLastPress > .nTimeOut
>      .cSearchString = ''
>    ENDIF
>    *** So now handle the key
>    DO CASE
>      CASE tnKeyCode = 7
>        *** If the delete key was pressed, reset the search string
>        *** and exit stage left
>        .cSearchString = ''
>        RETURN .T.
>      CASE tnKeyCode = 127
>        *** Backspace: Remove the last character from the Search string
>        IF LEN( .cSearchString ) > 1
>          .cSearchString = LEFT( .cSearchString, LEN( .cSearchString ) - 1 )
>        ELSE
>          .cSearchString = ''
>          RETURN .T.
>        ENDIF
>      OTHERWISE
>	*** A garden variety printable character
>	*** add it to the search string
>	.cSearchString = .cSearchString + CHR( tnKeyCode )
>    ENDCASE
>    *** Search for the closest match in the grid's record source
>    .Search()
>    *** Update value for keyPress interval timer
>    .tLastPress = DATETIME()
>  ENDWITH
>ELSE
>  *** Not a key we can handle
>  *** Let VFP handle it by default
>  This.cSearchString = ''
>  RETURN .F.
>ENDIF			
>
>
>and this code in the Search method:
>
>
>LOCAL lnSelect, lnCurRec, lcAlias
>
>*** Save Current work area
>lnSelect = SELECT()
>
>*** Get the grid's RecordSource
>lcAlias = This.Parent.Parent.RecordSource
>
>Thisform.LockScreen = .T.
>
>*** Search for the closes match to the Search string
>WITH This
>  *** Save the current record
>  lnCurRec = RECNO( lcAlias )
>  IF NOT EMPTY( .cTag )
>    *** Use an index tag if one exists	
>    IF SEEK( UPPER( .cSearchString ), lcAlias, .cTag )
>      *** Do nothing...we found a record
>    ELSE
>      *** Restore the record pointer
>      GO lnCurRec IN ( lcAlias )
>    ENDIF
>  ELSE
>    *** No Tag...have to use LOCATE
>    SELECT ( lcAlias )				
>    LOCATE FOR UPPER( EVAL( JUSTEXT( .Columns[ 1 ].ControlSource ) ) ) = ;
>      UPPER( .cSearchString )
>    IF NOT FOUND()
>      GO lnCurRec
>    ENDIF
>    SELECT ( lnSelect )
>  ENDIF				
>ENDWITH
>
>Thisform.LockScreen = .F.
>

>
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform