Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Click Grid control header to sorting the data in column
Message
From
10/10/2002 12:24:53
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00708196
Message ID:
00709915
Views:
30
I had try out the coding but the data in the grid still no change after click the different of grid header with particular order.

I cannot understand that because the code that I posted is in our book and I also have it working in serveral production apps. The only thing that I can think of is that you do not use my naming conventions, in which case it will not work. That is, if you have a field in your table called cName and it has an index tag on it, the name of the index tag must also be cName. If this is not the case, the code that I gave you will not work and you need to modify it to suit your needs.

If this is not what is causing your problem, then you need to step through the code and determine what is happening in your particular implementation. If you can narrow down the problems you are having, please come back with your specific questions and I will do my best to answer them. Unfortunately, telling me that it doesn't work on your machine, does not give me a great deal to work with < s >.

If I want to click the grid header first time the order will be ascending order and click second time the order will be descending order. Can I write the code like this:

First, I would not use a public variable. That is a bad idea. Second, I would not use a public variable called lnClick because the 'l' signifies that the variable is local in scope. I would add a property to my grid header called nClick. This means you need a custom header class like this to use in your grid:
DEFINE CLASS HdrBase AS Header
  nClick = 0
  *** Re-order the grid by tag (if it exists on this column
  FUNCTION Click
    *** set the nClick property
    WITH This
      .nClick = IIF( .nClick = 2, 1, .nClick + 1 )
      WITH This.Parent
        IF PEMSTATUS( .Parent, 'SetOrder', 5 )
          .Parent.SetOrder( JUSTEXT( .ControlSource ), .nClick )
        ENDIF
      ENDIF
    ENDWITH		
  ENDFUNC
ENDDEFINE
You can use your custom header class in your grid either by writing a builder for it or replacing the native grid headers using code in the grid's Init()

Then modify the grid's SetOrder method like this:
LPARAMETERS tcTag, tnClick
LOCAL lcOrd, lnrecNo
*** 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 )
      lcOrd = IIF( tnClick = 1, 'ASCENDING', 'DESCENDING' )
      SET ORDER TO ( tcTag ) &lcOrd      
      .SetFocus()
      IF lnRecNo # 0
        GO lnRecNo IN ( .RecordSource )
      ENDIF
    ENDIF
  ENDWITH					
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform