How To Scroll a TStringGrid dynamically? - delphi

I am working in the Borland C++Builder IDE, using VCL controls. I am trying to get a TStringGrid component to scroll down to a row and highlight that row, based on user input in a different form. I have the highlight portion done, but I can't figure out how to scroll the grid down to the correct row. Anyone here know?

Set the TopRow property.

Related

How to fix a column in TStringGrid with delphi FMX?

I want to make a grid with FireMonkey where it has a fixed column, but neither TGrid nor TStringGrid have that property, nor allow me to change it dynamically at runtime, as far as I can see.
Does anyone have a way to make this work?
Imagine I have 500 columns (I don't, and I won't have that number, this is just for demonstration purposes). I want to lock the first column so its content will always be visible as the user scrolls the grid along the X axis (horizontally). Same thing as with the header row, it's always locked in place so when the user scrolls along the Y axis, the header is always visible.
I am using Delphi 10.3.3 CE.

How to add a component to a TGrid column?

I am trying to add an EditBox and button (just as an example) to a Grid's Column as a child in Delphi 10.2/10.3. It looks fine during design-time, but completely disappears at runtime. As I assumed, those components are redrawn by the cells.
I've tried different simple steps, like reducing cell opacity, forcing them to be visible, bringing them to front, etc, but it nothing works.
In addition, the cells behind the components are not editable, so the components are blocking these cells but sort of invisible.
Is it possible to make them visible during runtime? I'd appreciate any ideas.
To clarify, I am not trying to fill rows and cells with these components. All that I need is to see and use them where I place them.

Problem with horizontal scrolling on TStringGrid [duplicate]

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

View position in DBGrid when scrolling in Delphi

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

Delphi - How to set vertical scrollbar in TStringGrid, always visible

I'm using Delphi 2007 for Win32 and need to set the vertical scrollbar in TstringGrid to always be visible. How do you do that?
You can hide scrollbars with the Scrollbar property set to either ssNone, ssHorizontal, ssVertical, even when the number of rows and / or columns would normally make them appear.
You can however not force one or both scrollbars to be always visible but disabled, without creating a new descendent class and overriding methods. Unfortunately the standard grid controls have not evolved much since the days of Delphi 1, so your best bet is using some third party grid control instead. Preferably one that does also show proper proportional scroll thumbs.
There is a scrollbar property that can be set to ssNone, ssHorizontal, ssVertical or ssBoth.

Resources