Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Click Grid control header to sorting the data in column
Message
De
06/10/2002 18:04:39
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00708196
Message ID:
00708230
Vues:
22
This message has been marked as the solution to the initial question of the thread.
My problem is using grid control to perform a sorting data as ascending or descending order when I click the grid header.

This is just one of the many tips we included in 1001 Things you Wanted to Know About VFP

Add a custom method called SetOrder to your grid class. This code goes in SetOrder():
LPARAMETERS tcTag

*** Make sure a valid tag name was passed
IF ! EMPTY( tcTag )
  WITH This
    *** Make sure it really is a tag for the grid's RecordSource
    IF IsTag( tcTag, .RecordSource )
      lnRecNo = RECNO( .RecordSource )
      *** Go ahead and set the order for the table
      SELECT ( .RecordSource )
      SET ORDER TO ( tcTag )
      .SetFocus()
      IF lnRecNo # 0
        GO lnRecNo IN ( .RecordSource )
      ENDIF
    ENDIF
  ENDWITH					
ENDIF


Here is IsTag.prg, which is used inside the SetOrder() method:
FUNCTION IsTag( tcTagName, tcTable )
LOCAL ARRAY laTags[1]
LOCAL llRetVal
*** Did we get a tag name?
IF TYPE( 'tcTagName' ) # 'C'
  *** Error - must pass a Tag Name
  ERROR '9000: Must Pass a Tag Name when calling ISTAG()'
  RETURN .F.
ENDIF
*** How about a table alias?
IF TYPE( 'tcTable' ) = 'C' AND ! EMPTY( tcTable )
    *** Get all open indexes for the specified table
    ATagInfo( laTags, "", tcTable )
ELSE
    *** Get all open indexes for the current table
    ATagInfo( laTags, "" )
ENDIF

*** Do a Case Insensitive, Exact=ON, Scan of the first column of array
*** Return Whether the Tag is Found or not
RETURN ( ASCAN( laTags, tcTagName, -1, -1, 1, 7 ) > 0 )
And this code in the Header's Click method:
WITH This.Parent
  IF PEMSTATUS( .Parent, 'SetOrder', 5 )
    .Parent.SetOrder( JUSTEXT( .ControlSource ) )
  ENDIF
ENDWITH		


Keep in mind that in order for this to work, if the table has an index tag on a certain field, the tag must have the same name as the field.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform