View position in DBGrid while scrolling in Delphi

I have a DBGrid in a form. DBGrid has many columns, so a horizontal scroller is displayed. I go through the DBGrid view on the right to see more columns. If I select a row, the DBGrid view will automatically reset to view the first column (as if I had scrolled back to the left position on the left).

Is there a way to prevent this?

+1


source to share


2 answers


I am assuming you have goRowSelect in your 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 in the view, the first visible column is not shown.



Since goRowSelect also effectively disables horizontal scrolling with the keyboard, I try to live without it. You can use a custom grid cell drawing to show all cells of the current row with the corresponding colors for the selected cells, even if only one cell is selected. I use this also to display different colors depending on whether the grid is focused or not, similar to what a standard tree control does. For this to work properly, you need to handle not only grid cell navigation events, but other events such as the OnEnter and OnExit of the grid, OnActivate and OnDeactivate of the application, etc.

+7


source


You might be able to query the position of the scrollbar

GetScrollInfo(Self.Handle, SB_VERT, SIOld);

      



and use SetScrollInfo( )

to get it back. Probably the best way. SelectedField

is another way (install / install it as needed).

+2


source







All Articles