ScrollInView usage ?

I'd like to be able to tell a grid to scroll to make the specified row
in the middle of the view if possible.  Is this what ScrollInView is
meant for?  I can't find it mentioned in the docs.

I'm revisiting this.

ScrollInView only seems to work if the specified row is not currently in view.  I want the grid to scroll so the specified row is as close to the middle of the visible rows area as possible.

Any answer would be nice.

I cannot see how it can be done better than what ScrollInView is doing now to bring a selected row in the vertical center of the visible rows:


procedure TForm1.Button1Click(Sender: TObject);
begin
  advstringgrid1.ScrollInView(1,250, spMiddle);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  advstringgrid1.RowCount := 1000;
  advstringgrid1.LinearFill(false);
end;

When I tried it in my code the scroll only happened if the chosen row was not already visible.

If the row was already in the visible section of the grid it did nothing.  I'll check in a test project.

Just tried your project and it only works if the chosen row is not currently visible.  Can that be changed?

Well, technically, ScrollInView is scroll-in-view. When it is already in view, it does not perform an (unneeded operation).
If you really need this to be ScrollInViewCentered, change the code to:


procedure TForm3.Button1Click(Sender: TObject);
begin
  advstringgrid1.TopRow := 1;
  advstringgrid1.ScrollInView(1,250, spMiddle);
end;

I understand what you're saying, but setting the top row isn't going to work for cases where the top row and desired row are already in the same view.

I will look at other ways to do it manually, or manipulate top row to make it work.