如何将 TDBGrid 记录视图恢复到刷新之前的状态?
我正在寻找一种在刷新发生后保存和恢复 Delphi TDBGrid
的垂直滚动位置的方法。目前,网格会自行重置,以便所选记录出现在记录列表的中间。
起初,属性 LeftCol
和 TopRow
似乎是解决方案,但只有 LeftCol
有效。 TopRow
值始终为 1 并且永不更改。它似乎是网格内部记录缓冲区中的一个位置,该位置设置为网格中显示的行数。也就是说,看起来 FBuffers 上下滑动,但 TopRow
始终保持 1。
我所看到的详细示例是:
- 网格显示
TClientDataSet
的 11 条记录,从记录 5 开始,按顺序显示到记录 15。 - 所选记录光标位于记录 15 上(最后一条记录)视图中)。
- 数据集通过链接到
TADODataSet
的TDataSetProvider
进行刷新。 (.Open 或.Refresh 调用)。 - dataset.Locate 方法用于在插入/删除时保留实际选定的记录。
- 网格发生变化,使得记录 15 位于中心,并且显示记录 10 到 20。
是否可以保存/恢复/执行任何操作,以便网格可以恢复到其原始查看配置,显示记录 5-15光标位于同一选定记录上,无论它出现在哪里?
在我的多次搜索尝试中,我能找到的最接近的东西是在 Delphi 3.0 中通过 TopRow、LeftCol 解决的问题,此处:http://www.delphigroups.info/2/79/314206.html
通过 DBGrids.pas 进行探索不是为我提供了一种相对于底层数据集记录定位缓冲区指针的方法。
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 aTADODataSet
. (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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎这些问题应该给你答案:
如何避免返回先前位置时 TDbgrid 滚动
Delphi - 恢复 DBGrid 中的实际行
(特别是这个答案)
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)