Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting in a Grid and stay at current recno()

Status
Not open for further replies.

schniesich

Technical User
Jul 28, 2005
11
DE
Hello,

I created a grid that can be sorted with a headers-click-event:
Code:
set order to xxx
thisform.refresh
That works quite well, but the datapointer does not remain on the same recno(), it jumps from click to click to differnet recno's.

This one also works perfectly:
Code:
set order to xxx
go top            && or go bottom
thisform.refresh
To remenber the last current recno() I tried this:
Code:
store recno() to act_rec
set order to xxx
goto (act_rec)
thisform.refresh
That work only when using the debugger and running step by step, but won't run/work when running the form without the debugger.

Does anyone has an idea how to get the current recno() to be displayed after setting the new order in a grid?

Thanks for help
Carsten.
 
Hi Mike,
thanks for the fast reply. Now I used "thisform.gridname.setfocus" in the headers-click-events, but that doesn't work either. I should say that I am using VFP 6.0 (SP5).

Thanks again,
Carsten.
 
Mike,

hard to say, always differnet ones. e.g. when starting from recno 3977 it goes on 2931 after the click event...

And after running the form again it will point to completly different recno's. ???

Carsten.
 

Carsten,

It's very strange. I don't understand this, and it's a pity no-one else has suggested anything.

One other possibility: Instead of saving the record number, how about saving the key value -- the one the index is based on.


For example, suppose the column you are indexing contains cust_id:

Code:
lcSave = cust_id
set order to cust_id
seek lcSave

Just a thought.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
how about being more precise in your code:
Code:
store recno("gridcursoralias") to act_rec
set order to xxx ascending in ("gridcursoralias") && or descending
* this shouldn't move the recordpointer, but neverthless:
goto act_rec in ("gridcursoralias")
thisform.grid1.setfocus()
* and even once again now:
goto act_rec in ("gridcursoralias")
Another thing is: Do you have any code in the BeforeRowColumnChange() or AfterRowColumnChange() and other events of the grid or the grid class you use, that may move the recordpointer?

Bye, Olaf.
 
store recno() to act_rec
set order to xxx
thisform.lockscreen = .t.
this.Parent.Parent.Visible = .f. &&hide grid
GOTO act_rec
this.Parent.Parent.Visible = .t.
this.Parent.Parent.SetFocus()
thisform.lockscreen = .f.
 
Hello Carsten.

Here is your solution:

Code:
KEYBOARD '{CTRL+TAB}'
lnRecNo = RECNO( This.RecordSource )
*** Go ahead and set the order for the table
SELECT ( This.RecordSource )
SET ORDER TO SomeTag
This.SetFocus()
IF lnRecNo # 0
  GO lnRecNo IN ( This.RecordSource )
ENDIF

Marcia G. Akins
 

Hi Marcia,

Could you explain your solution. It looks to my un-schooled eyes that the only difference between your code and some of the other suggestions is that you are Ctrl+Tabbing off the grid before doing anything else. I can't off-hand see how that would make a difference.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Wow, so many helpful people, thanks a lot for the answers!!!

how about being more precise in your code
This one did it, thanks OlafDoschke!
I just moved from FP2.6 and since I am only a "hobby" programmer, I am lost many times.

When changing the order in an open table from the command-window the pointer does not move, that's why I was wondering why the pointer moves in a grid. There are no filters set and I was not dealing with deleted records. In AfterRowColumnChange() is only another refresh.

Thanks again for your wonderful assistance!
Carsten.
 

Marcia,

There can be refresh issues if the grid has focus when you are manipulating its RecordSource. Tabbing off the grid take these issues out of play.

Ah, yes. I thought it might be a refresh issue (as per my first post), but it wouldn't have occurred to me to move focus off the grid beforehand. Thanks.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi again,
I just found out that it is not only a question in precision of the code. I just had "thisform.grid1.setfocus()" in the wrong place. It has to be placed before the "GOTO" command and not after it! Never the less it semms that a precise code is very impotant.

Thank you all for your inputs.
Carsten.
 
Thanks to all who contributed - I just hit the same problem and wow - here's the answer. This a great facility with some great contributors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top