在 Delphi 中滚动时查看 DBGrid 中的位置

发布于 2024-07-09 20:53:35 字数 144 浏览 11 评论 0原文

我在表单上有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌生 2024-07-16 20:53:35

我假设您的网格选项中有goRowSelect。 这会强制选定的列成为第一个非固定列,因此每当行更改时,将选定的单元格滚动到视图中的代码都会强制第一个非固定列可见。

由于 goRowSelect 还有效地禁用了键盘的水平滚动,因此我尝试在没有键盘的情况下生活。 您可以使用网格单元格的自定义绘图来显示当前行的所有单元格,并使用所选单元格的正确颜色,即使实际上只选择了一个单元格。 我还使用它来根据网格是否聚焦来显示不同的颜色,类似于标准树控件的作用。 为了使其正常工作,您不仅需要处理网格单元格导航事件,还需要处理一些其他事件,例如网格的 OnEnterOnExitOnActivate 和应用程序的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.

故笙诉离歌 2024-07-16 20:53:35

您也许可以请求滚动条位置

GetScrollInfo(Self.Handle, SB_VERT, SIOld);

并使用SetScrollInfo( ) 将其放回原处。 可能有更好的方法。 SelectedField 是另一种方式(根据需要获取/设置它)。

You might be able to ask for the scrollbar position

GetScrollInfo(Self.Handle, SB_VERT, SIOld);

and use SetScrollInfo( ) to put it back. There's probably a better way. SelectedField is another way (get/set it as needed).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文