View position in DBGrid when scrolling in Delphi

后端 未结 2 907
走了就别回头了
走了就别回头了 2020-12-22 01:42

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 r

相关标签:
2条回答
  • 2020-12-22 02:02

    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).

    0 讨论(0)
  • 2020-12-22 02:09

    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.

    0 讨论(0)
提交回复
热议问题