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!

Maintain Relative Position in Grid

Status
Not open for further replies.

KALP1

Programmer
Aug 26, 2016
102
IN
Say I have 20th record at grid's row no. 5. After refresh i want same 20th record at grid's row no. 5

I found similar threads in the forum but couldn't get accurate answer for that
 
After what refresh? Form.Refresh() shouldn't move the record pointer and visible record in grids. Grid.Refresh also not. When you requery or reset the recordsource obviously you're back to top of the grid alias, so mainly move to the 20th record, eg SKIP 19 and then adjust the positioning with doscroll.

Bye, Olaf.
 
I am recreating grid cursor.
My problem is even after setting focus on grid,activerow and relativerow properties are coming 0.
After writing Skip 19,relativerow comes to be 0 but Doscroll scrolls grid from somewhere middle of the grid i.e It seems cursor was somewhere in the middle ,so what to do to get relativerow
 
help file said:
ActiveRow returns zero if the grid doesn't have the focus or when you access a row outside the grid display.

So the grid has to have focus, so you need Thisform.yourgrid.setfocus()

Bye, Olaf.
 
even after setting focus on grid
I have set focus on the grid -> Thisform.gridname.setfocus, then too both values are coming 0.
 
Did you first GOTO the record number you want displayed? Does the grid at least move that row into it's first display row? Or do you have the typical grid goes blank effect? You can't rebuild the grid alias/cursor at runtime with a simple INTO CURSOR samename query. Either you ZAP and SELECT INTO the current grid cursor (which has to be readwrite for that and absolutely not the underlying table) or you temporarily set grid.recordsource="" at least, otherwise nothing will display any data in the grid, from the moment on you rebuild the grid alias name, ie from a SELECT ... INTO CURSOR onwards, because while that regenerates the cursor, in the first moment it's closed and that's when the grids binding is lost, thus the grid loses all it's columns and column controls, and they don't come back next moment.

I actually don't assume you have the grid blanking effect, because that's a much bigger problem than just navigating back to some active row.

Bye, Olaf.
 
Yes, grid moved to that record. No,I don't have blanking effect. What exactly is happening is
Say I am on record 20th of the grid. I refreshed cursor and then issued Goto command. Grid moved to that row. At this particular moment, I had setfocus on grid and activerow and relativerow are returning 0 values. Then I issued Doscroll event in for-endfor loop, after 1-2 Doscroll, activerow and relativerow are returning correct values. I want these values before beginning of for-Endfor Loop.
 
How about doing this, it is a Foxpro command, DOEVENTS. put it right after the line setting the focus, so the focus can get into effect and ActiveRow/RelativeRow is set.

Bye, Olaf.
 
Great Olaf, It worked. Now both properties are giving correct values.

Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top