在 Delphi 中滚动时查看 DBGrid 中的位置
我在表单上有一个 DBGrid。 DBGrid 有很多列,因此会显示水平滚动条。 我向右滚动 DBGrid 视图以查看更多列。 如果我选择一行,DBGrid 视图会自动重置以查看第一列(就像我滚动回最左边的位置一样)。
有办法防止这种情况吗?
I have a DBGrid on a form. The DBGrid has many columns, so an horizontal scroller is displayed. I scroll the DBGrid view to the right to see more columns. If I select a row, the DBGrid view is automatically reset to view the first column (As if I scroll back to the left most position).
Is there a way to prevent that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您的网格选项中有goRowSelect。 这会强制选定的列成为第一个非固定列,因此每当行更改时,将选定的单元格滚动到视图中的代码都会强制第一个非固定列可见。
由于 goRowSelect 还有效地禁用了键盘的水平滚动,因此我尝试在没有键盘的情况下生活。 您可以使用网格单元格的自定义绘图来显示当前行的所有单元格,并使用所选单元格的正确颜色,即使实际上只选择了一个单元格。 我还使用它来根据网格是否聚焦来显示不同的颜色,类似于标准树控件的作用。 为了使其正常工作,您不仅需要处理网格单元格导航事件,还需要处理一些其他事件,例如网格的 OnEnter 和 OnExit、OnActivate 和应用程序的OnDeactivate,等等。
I assume you have goRowSelect in the grid options. This forces the selected col to be the first non-fixed column, so whenever the row changes the code to scroll the selected cell into view forces the first non-fixed column to be visible.
Since goRowSelect also effectively disables the horizontal scrolling with the keyboard I try to live without it. You can use custom drawing of the grid cells to show all cells of the current row with the proper colours for selected cells, even though only one cell is really selected. I use this also to show different colours depending on whether the grid is focused or not, similar to what a standard tree control does. For this to work properly you do however need to handle not only grid cell navigation events, but some other events too, like OnEnter and OnExit of the grid, OnActivate and OnDeactivate of the Application, and so on.
您也许可以请求滚动条位置
并使用
SetScrollInfo( )
将其放回原处。 可能有更好的方法。SelectedField
是另一种方式(根据需要获取/设置它)。You might be able to ask for the scrollbar position
and use
SetScrollInfo( )
to put it back. There's probably a better way.SelectedField
is another way (get/set it as needed).