See following code. I used it in my grid class to center grid position after sorting (you know, sorting rearranges lines, so line may become last in grid and scroll up all other lines...). I recommend also to include it into bounds of screen locking (LockScreen property of form), so users will not see how row goes top and back.
procedure RefreshAfterSorting
with this
local lcOldArea, lcGridAlias
m.lcOldArea = select(0)
m.lcGridAlias = this.GetGridAlias() && just get tied record source alias
&& it may be SQL, so I made function
select (m.lcGridAlias)
* store 'real' grid position, this is needed because it may change in the next chapter
local nOldRecNo
m.nOldRecNo = .nRecno && stored record number in grid property in the AfterRowColChange event. Do not use recno() at this moment, it may be invalid
&& reset row position
* this must be BEFORE any refresh of grid in all previous commands
if between(m.nOldRecNo,1,reccount())
go Top
ENDIF
.Refresh()
* return record number back
&&&& NOTE at this point you need experimenting.
&&&& Sometimes (very rare) I got unpredictable results, but when I put
&&&& this.Column*.SetFocus - all ok. So if you have problems, use
&&&& this too.
if between(m.nOldRecNo,1,reccount())
go (m.nOldRecNo)
ENDIF
.Refresh()
select (m.lcOldArea)
DOEVENTS && very useful, verified
endwith
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.comICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs
It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.