在Delphi中滚动时查看DBGrid中的位置 [英] View position in DBGrid when scrolling in Delphi

查看:187
本文介绍了在Delphi中滚动时查看DBGrid中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有一个DBGrid。 DBGrid有很多列,所以显示一个水平滚轮。我向右滚动DBGrid视图查看更多列。如果我选择一行,DBGrid视图将自动重置以查看第一列(如果我向后滚动到最左边的位置)。



有没有办法防止这种情况?

解决方案

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



由于 goRowSelect 也有效地禁用了使用键盘的水平滚动,我试图没有它。您可以使用网格单元格的自定义绘图来显示所选单元格的正确颜色的当前行的所有单元格,即使只选择了一个单元格。我也使用它来显示不同的颜色,这取决于网格是否聚焦,类似于标准树控件。为了正常工作,您需要处理不仅网格单元导航事件,还需要处理网格的 OnEnter OnExit 等其他事件,OnActivate 和 OnDeactivate ,等等。


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?

解决方案

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.

这篇关于在Delphi中滚动时查看DBGrid中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆