How can I restore a TDBGrid record view to the condition before a refresh? [duplicate]

StackOverflow https://stackoverflow.com/questions/8793857

  •  15-04-2021
  •  | 
  •  

Question

Possible Duplicate:
How to avoid TDbgrid scrolling when returning to a previous location

I am looking for a way to save and restore the vertical scrolling position of a Delphi TDBGrid after a refresh has occurred. Currently, the grid resets itself so that the selected record appears in the middle of the list of records.

At first, the properties LeftCol and TopRow appeared to be the solution, but only LeftCol works. The TopRow value is always 1 and never changes. It appears to be a position into the internal record buffer of the grid, which is set to the number of rows displaying in the grid. That is, it appears that FBuffers slides up and down, but TopRow remains 1 at all times.

A detailed example of what I'm seeing is:

  • The grid displays 11 records of a TClientDataSet, starting with record 5, displayng sequentially to record 15.
  • The selected record cursor is on record 15 (the last record in the view).
  • The dataset is refreshed through a TDataSetProvider linked to a TADODataSet. (An .Open or .Refresh call).
  • The dataset.Locate method is used to retain the actual selected record in the face of insertions/deletions.
  • The grid changes so that record 15 is in the center and it is displaying records 10 through 20.

Is there anything that can be saved/restored/performed so that the grid can be restored to its original viewing configuration showing records 5-15 with the cursor on the same selected record, wherever it appears?

The closest thing I can find in my many search attempts is an issue that was solved in Delphi 3.0 with TopRow, LeftCol, here: http://www.delphigroups.info/2/79/314206.html

Spelunking through DBGrids.pas isn't netting me a method of locating the buffer pointers relative the underlying dataset records either.

Was it helpful?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top