2

I need a string grid which can scroll smoothly, as opposed to locking in the top row / left col positions. When you scroll a TStringGrid, the left visible column and top visible row snap into position along the top/left edges. I need the ability for the user to scroll smoothly, not locking these edges into place.

I wouldn't think this is possible to modify in the VCL TStringGrid (or TCustomGrid for that matter) because it relies on properties such as TopRow, LeftCol, VisibleRowCount, etc.. I'm pretty sure I'll need a third party control, but I'd love to use the TStringGrid if possible, because I already have a lot of code wrapped around it. If I do need a third-party grid, then I'm hoping it works closely enough like the TStringGrid.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • I have no idea what you're asking for here. Are you talking about horiz. or vertical scrolling? What does "snap into position" mean, or "locking these edges into place"? I've used `TStringGrid` extensively, and have no clue what behavior you're objecting to or what you're trying to ask here. – Ken White Aug 17 '12 at 01:10
  • When you scroll, either vertically or horizontally, it moves one column/row at a time. – Jerry Dodge Aug 17 '12 at 02:21
  • But that's the way grids work, for instance the ones used in Excel. A partial row of data in a grid is not useful. If you don't want that behavior, you're using the wrong control. – Ken White Aug 17 '12 at 02:25
  • The FMX grid has an 'animated' property which matches to what you seem to look for...however it's not the VCL... – az01 Aug 17 '12 at 07:56
  • @KenWhite It depends on how you intend to use it. Sure, if it's just showing text, then the first row isn't useful. But what about a column which is 3/4 the width of the control? When I scroll over, it jumps cell by cell instead of pixel by pixel, and a wide cell would cause a big jump. – Jerry Dodge Aug 17 '12 at 18:27

2 Answers2

6

The short answer is no, you can´t pixel scroll a TStringGrid. You can simulate a grid using a TScrollBox. You can put a grid inside the TScrollBox, make the grid large enough to fit all rows and cols, and turn off its scroll bars, but some things like keyboard navigation will not work.

Other alternative is to use the TVirtualTree in grid mode or TListView. Both have this pixel scroll you want.

NGLN
  • 43,011
  • 8
  • 105
  • 200
  • 1
    On putting a string grid inside a scroll box, you then would need 3 string grids; one for the row headers, one for the column headers, and one for the data region. – NGLN Aug 17 '12 at 04:43
  • 3
    Why not use and learn a proffessional grid like devexpress http://www.devexpress.com/Products/VCL/ExQuantumGrid. – Roland Bengtsson Aug 17 '12 at 05:10
  • I'll give the `TVirtualTree` a shot, but the `TListView` is way too heavy (I didn't mention I moved from `TListView` to `TStringGrid` because of performance on hundreds of thousands of items). The `ExQuantumGrid` looks hopeful too, worthy of another answer. – Jerry Dodge Aug 17 '12 at 15:27
  • If performance is an issue, and in light of your original question, it's really worth the effort to learn to use TVirtualTree. It's a chance in paradigm, but once you "get" it, it'll pay off in a big way. – Argalatyr Aug 17 '12 at 17:22
0

I was looking for something similar. Unfortunately, you can't do it with Borland's code but Lazarus can do it Scrolling the TStringGrid pixel by pixel
You may want to take a look in their code.

Community
  • 1
  • 1
Gabriel
  • 20,797
  • 27
  • 159
  • 293