Recent

Author Topic: Set TStringGrid scroll event to TScrollBox scroll event  (Read 6766 times)

corpusgemini

  • New Member
  • *
  • Posts: 19
Set TStringGrid scroll event to TScrollBox scroll event
« on: November 27, 2014, 07:49:09 pm »
Hello,

I have a TStringrid with a Tscrollbox as a parent.
I would like to trigger the scrollbox to scroll when my mouse is inside the stringgrid instead of the selected cell rectangle moving around in the stringgrid.

How is this possible?

Thanks,
Tony

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Set TStringGrid scroll event to TScrollBox scroll event
« Reply #1 on: November 27, 2014, 11:57:15 pm »
I think this may only be possible by writing your own grid component which either intercepts LM_HSCROLL and LM_VSCROLL messages or descends from TCustomScrollBox.
Automatic scrolling is built in to the design of TStringGrid, and I cannot see any methods or properties that would let you turn autoscrolling off, or handle scrolling externally. The grid's Scrollbars property affects the display of scrollbar(s), but does not change the built-in scrolling behaviour, so a TStringGrid will scroll whether or not it sports scrollbars.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Set TStringGrid scroll event to TScrollBox scroll event
« Reply #2 on: November 28, 2014, 12:05:40 am »
Hello,

I have a TStringrid with a Tscrollbox as a parent.
I would like to trigger the scrollbox to scroll when my mouse is inside the stringgrid instead of the selected cell rectangle moving around in the stringgrid.

How is this possible?

Thanks,
Tony

I'm guessing that you have the stringgrid set to alclient alignment which is the same as using a simple panel as the container. If you want to use the scrollbox scrolling capabilities instead of the grids then you need to align the grid altop and calculate its height based on the rows it has so it will not have any scroll bars it self and even then you need to change the lazarus default wheel behavior to allow the scrollbox to  handle the scrolling by forwarding  the message to it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

corpusgemini

  • New Member
  • *
  • Posts: 19
Re: Set TStringGrid scroll event to TScrollBox scroll event
« Reply #3 on: November 28, 2014, 05:18:34 pm »
Hello,

Thanks a lot for your suggestions.
The Stringgrid indeed has alClient alignment.
I ended up using the stringGrid.OnmouseWheel event to alter the position of the vertical scrollbar of the scrollbox with WheelDelta.
Also, I had to change the stringgrid option [goDontScrollPartCell] to True, to avoid my stringgrid moving one row too far up.

This is solved now.

Cheers,
Tony

 

TinyPortal © 2005-2018