×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Getting to the top row of a grid

Getting to the top row of a grid

Getting to the top row of a grid

(OP)
I have a grid that has a table as a recordsource.  There are 8 columns & when you click on a header, it sorts by that column.  The problem is when I try to sort twice (IE: I click on header A then Header B).  If record #1 isn't the first record in the new sort, the grid will show the 5th record as the 1st record in the grid.  You just have to scroll up to see the rest of the records, but I would like to have the grid show the first record no matter what field I'm sorting on.  Here is the code I have in the click event for each header in my grid:

SELECT GRIDINFO
INDEX ON FCUBEDID TAG PALLETID
SET ORDER TO PALLETID
GO TOP

WITH THISFORM.GRDXDOCKINFO
    .RECORDSOURCETYPE = 1
    .RECORDSOURCE = "GRIDINFO"
ENDWITH    

THISFORM.CMDRESET.SETFOCUS
THISFORM.REFRESH

Any help would be greatly appreciated.

RE: Getting to the top row of a grid

I'm not sure if it will be the sole solution, but you can try the DoScroll method.

-----------------
Robert Bradley
use coupon code "TEKTIPS" for 15% off at:
http://www.lowcostprints.com
http://www.foxdev.com

RE: Getting to the top row of a grid

HI
What is the code in ...
THISFORM.CMDRESET.SETFOCUS

Can you try adding at the end..
(probably instead of ThisForm.Refesh() if nothing else need to be reset)..
THISFORM.GRDXDOCKINFO.Refresh()
THISFORM.GRDXDOCKINFO.SetFocus

ramani
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK

RE: Getting to the top row of a grid

Hi,

The way I have dealt with this is to set the grid's RecordSource to [], sorted the table and then set the RecordSource back again. I'm using it on a small table and there is a noticeable blink, but this might be eliminated if you set the form's LockScreen propery to .T. at the start and setting it back to .F. at the end.

To do this, I have added a method to my grid base class as follows:

LPARAMETER Param1
WITH THIS
    .RecordSource = []
    .SetAll([BackColor],RGB(192, 192, 192),[Header])
    FOR Counter = 1 TO .ColumnCount
        IF .Columns(Counter).Header1.Caption = Param1 OR .Columns(Counter).Header1.Tag = Param1
            .Columns(Counter).Header1.BackColor = RGB(0, 255, 0)
            EXIT
        ENDIF
    ENDFOR
    IF VARTYPE(Param1) <> [L]
        .Sort(Param1)
    ELSE
        .Sort
    ENDIF
ENDWITH


This changes the colour of the header on which you have sorted, making it obvious to the user. In my situation, each column header calls this method with it's caption, but you could call it with an index tag or whatever.

This method then calls the grid's sort method. This is empty in the base class so I can enter code there when I place the grid on a form. Of course the sort method must set the RecordSource back again!

For me this has given what you seem to be asking for.

Hope it helps,

Stewart

RE: Getting to the top row of a grid

Hi,

The way I have dealt with this is to set the grid's RecordSource to [], sorted the table and then set the RecordSource back again. I'm using it on a small table and there is a noticeable blink, but this might be eliminated if you set the form's LockScreen propery to .T. at the start and setting it back to .F. at the end.

To do this, I have added a method to my grid base class as follows:

LPARAMETER Param1
WITH THIS
    .RecordSource = []
    .SetAll([BackColor],RGB(192, 192, 192),[Header])
    FOR Counter = 1 TO .ColumnCount
        IF .Columns(Counter).Header1.Caption = Param1 OR .Columns(Counter).Header1.Tag = Param1
            .Columns(Counter).Header1.BackColor = RGB(0, 255, 0)
            EXIT
        ENDIF
    ENDFOR
    IF VARTYPE(Param1) <> [L]
        .Sort(Param1)
    ELSE
        .Sort
    ENDIF
ENDWITH


This changes the colour of the header on which you have sorted, making it obvious to the user. In my situation, each column header calls this method with it's caption, but you could call it with an index tag or whatever.

This method then calls the grid's sort method. This is empty in the base class so I can enter code there when I place the grid on a form. Of course the sort method must set the RecordSource back again!

For me this has given what you seem to be asking for.

Hope it helps,

Stewart

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close