刷新DBGrid后选择行
好吧,这是我提出的一些n00b问题。我在这里上网和类似的问题,但没有找到这样简单(正如我认为的)问题的任何正确答案。
我有一个数据库网格。我选择一行并使用链接到该行的另一个数据执行一些操作。完成后,我的 DBGrid 被刷新,所选行重置为第一行。我想要选择刷新 DBGrid 数据之前选择的同一行。有什么建议吗?
Well, some kind of n00b question from me. I've surfed the net and similar questions here but haven't found any right answers for such simple (as I thought) problem.
I have a DBGrid. I select one row and make some actions with another data linked to this row. After I finished, my DBGrid being refreshed and selected row resets to first. I want to get the same row selected that was selected before refreshing DBGrid data. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
刷新之前,将链接数据集的当前选择保存为书签,然后恢复书签。
Before refreshing, save the linked dataset's current selection as a bookmark, then restore the bookmark afterwards.
这个答案旨在作为梅森的一个小补充,而不是替代。我添加它只是因为出现了另一个答案,在我看来,错误地建议使用数据集的 RecNo 属性。并非所有 TDataSet 后代都可靠地或根本无法实现 RecNo。某些后代仅返回一个常量值,例如当前行的 RecNo 为 0,并且当您为其赋值时不执行任何操作。
This answer is intended as a minor supplement to Mason's, not an alternative. I've added it only because another answer has appeared, suggesting, incorrectly imo, the use of the dataset's RecNo property. Not all TDataSet descendants implement RecNo reliably or at all. Some descendants just return a constant value e.g. 0 for the current rows's RecNo and do nothing when you assign a value to it.