Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-10

Synchronize scrollposition of two stringgrids

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rimmert Ooink

Hello,

I have two stringgrids with exactly the same columns, basically something like Excel autofilter.

Does anybody have an idea how to change the scrollposition of a stringgrid depending on the scrollpos of the other?

It seems i can use the ontopleftchanged event, but i dont know how to get or set the scrollposition.

Tanks a lot,

Rimmert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20121015/5d88e182/attachment.html>

Reply by email

Jesus Reyes
to Rimmert Ooink
I have two stringgrids with exactly the same columns, basically something like Excel autofilter. Does anybody have an idea how to change the scrollposition of a stringgrid depending on the scrollpos of the other?

One way would be using OnSelection event and try something like:

sg1.LeftCol := sg2.LeftCol;
sg1.TopRow:=sg2.TopRow;

sg1 will be synchronized to sg2.

That would give you row/col size granularity. For pixel granularity, without messing with grids internals, could be done using GetScrollInfo for both scrollbars on source grid and using SetScrollInfo for both scrollbars on target grid. Not tried but should work :)

Jesus Reyes A.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20121015/e3153fc5/attachment.html>

Reply by email

Rimmert Ooink
to Jesus Reyes
Jesus Reyes wrote 12 lines
>Does anybody have an idea how to change the scrollposition of a stringgrid depending on the scrollpos of the other? sg1.LeftCol := sg2.LeftCol; sg1.TopRow:=sg2.TopRow; That would give you row/col size granularity. For pixel granularity, without messing with grids internals, could be done using GetScrollInfo for both scrollbars on source grid and using SetScrollInfo for both scrollbars on target grid. Not tried but should work :) LeftCol works like described.

I also want to try the Get/SetScrollInfo, but I noted it is defined in winapih, does that mean its Windows only?
Ifso, i'll stick with using Leftcol.

(The program will be used on Mac and Win, but i dont have a mac machine atm.)

Thanks,
Rimmert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20121016/1475a012/attachment.html>

Reply by email

Sven Barth
to Rimmert Ooink
Rimmert Ooink wrote 20 lines
On Tue, Oct 16, 2012 at 1:54 AM, Jesus Reyes < <mailto:>> wrote: >Does anybody have an idea how to change the scrollposition of a stringgrid depending on the scrollpos of the other? sg1.LeftCol := sg2.LeftCol; sg1.TopRow:=sg2.TopRow; That would give you row/col size granularity. For pixel granularity, without messing with grids internals, could be done using GetScrollInfo for both scrollbars on source grid and using SetScrollInfo for both scrollbars on target grid. Not tried but should work :) LeftCol works like described. I also want to try the Get/SetScrollInfo, but I noted it is defined in winapih, does that mean its Windows only? Ifso, i'll stick with using Leftcol.

winapih only means that this is the file where the declarations of the Windows API functions reside which are used (and implemented) by the LCL on all plattforms (even on Windows the routines there are forwarders to the real Win API functions). So if Get-/SetScrollInfo is implemented and works for e.g. Carbon you can use it.

Regards,
Sven

Reply by email

Rimmert Ooink
to Rimmert Ooink: I also want to try the Get/SetScrollInfo, but I noted it is defined in winapih, does that…
Rimmert Ooink wrote 6 lines
On Tue, Oct 16, 2012 at 1:54 AM, Jesus Reyes wrote: > >> Does anybody have an idea how to change the scrollposition of a stringgrid depending on the scrollpos of the other? > sg1.LeftCol := sg2.LeftCol; > > For pixel granularity, without messing with grids internals, could be done using GetScrollInfo for both scrollbars on source grid and using SetScrollInfo for both scrollbars on target grid.

Anybody an idea why the code below doesn't work?
GetScrollBarPosition does seem to return the correct value, but the call to ScrollbarPosition doesn't seem to work.
On windows it actually cals SetScrollInfo as mentioned, but doesn't seem to do anything.

Thanks!

type
  TGridHack = class(TStringGrid)
  public
    procedure SyncTo(grd: TStringGrid);
  end;
implementation

{ TGridHack }

procedure TGridHack.SyncTo(grd: TStringGrid);
begin
  //LeftCol := grd.LeftCol;
  ScrollBarPosition(SB_Horz, TGridHack(grd).GetScrollBarPosition(SB_Horz));
  //ScrollBarPosition(SB_Vert, TGridHack(grd).GetScrollBarPosition(SB_Vert));
end;

Reply by email