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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preserving visual position of current record in grid after refresh 1

Status
Not open for further replies.

awaresoft

Programmer
Feb 16, 2002
373
DE
Is there a best practice technique for preserving the visual POSITION of the current record in a grid after the grid's record source is refreshed?

For example, if the current record in a grid is displayed in visual row 4 of 10 rows and I refresh the grid's record source, how do I make sure that the current record remains in visual row 4 after the refresh. (This assumes that the current record remains in the record set and that each record has a primary key to seek on)

I'm thinking that I need to use some combination of ActiveRow, RelativeRow and possibly the DoScroll() to fine the visual position.

Any thoughts on doing this in a generic manner?

Malcolm
 
CORRECTION: I meant to say "requeried" vs. "refresh" - in other words, I'm looking for a way to preserve a grid's current record's relative position in the grid after the grid's underlying record source has been updated with a new set of records.

You can assume that each record has a primary key that can be seeked on and that the grid's current record is present in the updated record source.

Thank you,

Malcolm
 
Hi Malcolm.

I don't understand why nobody responses. Probably not a good practice to add first response to own question immediately and make total number of replies non zero.

I have not a complete solution at hand, but I think that the key to your problem is a DoScroll() Method in conjunction with RelativeRow property.

In your updated record source place the pointer to desired position and apply DoScroll()Method until RelativeRow reaches the desired value.

It is clear, that this can't be accomplished under all circumstances, so look out on (for?, sorry for my English) endless loops.

Also remember, that RelativeRow returns appropriate results only if your grid is active, so thisform.grid1.setfocus before every RelativeRow reeding is needed.

It is still lot of work, but I hope this help.

Tom.
 
Tom,

Thank you for your ideas. You are right - DoScroll() is the key. And so is setting focus to the grid so RelativeRow can be queried. There are still some odd cases to work out - sometimes RelativeRow is not updated when a grid gains focus at remains at 0.

Thanks again for contributing to this thread,

Malcolm

BTW: You English is very good. No apologies needed :)
 
Tom,

Probably not a good practice to add first response to own question immediately and make total number of replies non zero.

That suggests that people will be more likely to open a thread if there are no replies posted yet. I wonder if that's true.

In any case, how else would the person posting the question add clarifications and follow-ups to his/her question.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
This is what I have been using, keep in mind if you delete a record you have to SKIP -1 or +1 to get the closest key value. It works best to use a table key value since the recordnumber can change depending on the sort order:

lnCurrKey = MyTable.Key_Value
ThisFOrm.grdMyGrid.RecordSource = ""
** REQUERY OR WHATEVER METHOD OF RENEWING DATA
ThisForm.grdMyGrid.RecordSOurce = "MyTable"
SELECT MyTable
Index on Key_Value tag indxtag ADDITIVE
llFound=SEEK(lnCurrKey,"MyTable","IndxTag")
IF llFound = .F.
GO TOP
ENDIF
ThisForm.grdMyGrid.Refresh()

Regards,

Rob
 
Rob,

Your code works great for restoring the previously active record, but it does not preserve the record's relative row setting across refreshes.

I'm using doscroll() to position my reselected record to its former relativerow. This works, it just seems very inefficient and has the added drawback that focus must be set to the grid so relative row will return a value. Also, the relativerow property is kind of "funky" and does not always update itself when a grid gets focus.

Thanks for your suggestion.

Malcolm
 
If you add 'GO BOTTOM' just before the seek then the relative row will stay in the middle which is how I handle it in my current app. I use this same method when users click on column headers to maintain the row regardless of how the table is resorted.

Regards,

Rob
 
Rob,

Thanks for the clarification. My users want to preserve their record's relativerow position when refreshing the grid, but I can see an advantage in the consistency of 'middle-of-the-grid' positioning as well.

Malcolm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top