5

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.

Community
  • 1
  • 1
cdburgerjr
  • 175
  • 2
  • 9

1 Answers1

6

Seems that these questions should give you the answer:
How to avoid TDbgrid scrolling when returning to a previous location
Delphi - restore actual row in DBGrid
(esp. this answer)

Community
  • 1
  • 1
Francesca
  • 21,156
  • 3
  • 46
  • 87
  • I was the OP of the François' first link ("How to avoid...") and implemented Sertac's solution ("esp. this answer") last month. It has worked wonderfully for me. – RobertFrank Jan 10 '12 at 00:32
  • I incorporated the "esp. this answer" into my solution. It is working very well. Kind of wish I'd spotted it before posting a dupe, but thanks so much for pointing me in the right direction. – cdburgerjr Jan 10 '12 at 00:38