TAdvSmoothScrollBar - Detect line & page up/down

My client really loves the look of the TAdvSmoothScrollBar when I set "FixedThumb=True" and set "Rounding=8".

I'm just having problems getting it to function like the built in scroll bar on TAdvStringGrids. Once I get this working I'll also need it working on THTMLTreeviews.

The docs for TAdvSmoothScrollBar say it's based on TScrollBar. TScrollBar has an OnScroll event with TScrollCode that tells me what the user is trying to do. I don't see anything like this with TAdvSmoothScrollBar. Not that I've ever used TScrollBar, I've always just used the built in scroll bars.

To work around this - at least for line up and down - I've tried this code below. Please note that Grid is an input parameter (using TAdvSmoothScrollBar.OnPositionChanged) so that I can pass in any TAdvStringGrid and TAdvSmoothScrollBar into this one piece of code.

   // if we're moving up and we're not already at the top
   if (Position < Grid.TopRow - Grid.FixedRows) and (Grid.TopRow > Grid.FixedRows) then
      Grid.TopRow := Grid.TopRow - 1
   // else if we're moving down and we're not already at the bottom
   else if (Position > Grid.TopRow - Grid.FixedRows) and (Grid.TopRow + Grid.VisibleRowCount < Grid.RowCount) then
      Grid.TopRow := Grid.TopRow + 1;

It works okay, but there are times when, if I use the thumb to scroll, I have to click up or down several times before it starts to move. And the Thumb does not work corectly at all. I barely start to move the thumb down and the grid hits the bottom long before the thumb hits the bottom of its control.

I can solve this problem easily by changing OnPositionChanged to use percetage of the scroll to set Grid.TopRow, but then the arrows don't work correctly. I often have to click the up/down arrows multiple times before it starts to move.

Also, the only way I can think of to do page down (when the user clicks below the thumb button and above the down arrow) is the look at OnMouseDown and get the position of the mouse and check and see if it's below the thumb and above the arrow. That sounds like a real mess.

Here is my code for setting the thumb/page size (which gives me the size of thumb I think I need):

procedure sizeGridAndScrollBar(Grid : TAdvStringGrid; ScrollBar : tAdvSmoothScrollBar);
begin
   // Do we need a scroll bar?
   if Grid.RowCount - Grid.FixedRows > Grid.VisibleRowCount then
   begin
      Grid.Width := ScrollBar.Left - Grid.Left + 2;
      ScrollBar.PageSize := 100 - (Grid.RowCount - Grid.FixedRows - Grid.VisibleRowCount) - 1;
      ScrollBar.Show;
   end
   // else we don't need a scroll bar
   else
   begin
      Grid.Width := ScrollBar.Left + ScrollBar.Width - Grid.Left;
      ScrollBar.Hide;
   end;
   ScrollBar.Top := Grid.Top + 1;
   ScrollBar.Height := Grid.Height - 2;
end;

Do you have some sample code of how I should be doing all this?

Thanks,
Mike

Sorry, we have at this moment no ready to use code to integrate a TAdvSmoothScrollBar for TAdvStringGrid. We have never implemented such coupling before. 

To synchronize this will not be trivial. First of all, to handle clicking before or after the thumb, please use the property AdvSmoothScrollBar.LargeScale to configure the position change for this type of scrolling. Secondly, if you click the scroll up & scroll down buttons, the position changes with +1 or -1. It will depend on your calculation whether that will result in an actual move of rows up or down. For this to synchronize with moving grid rows up or down, you'd need to set AdvSmoothScrollBar.Max to the nr. of rows in the grid I believe.