[delphi-users:1048] 2つのTStringGridのスクロールを同期したい

473 views
Skip to first unread message

hosoi

unread,
Apr 8, 2010, 8:05:34 AM4/8/10
to delphi...@freeml.com
細井というものです。

フォームに同じ大きさのStringGridを2つ配置し、そのStringGridのスクロール
を同期させたいと思っています。

下記URLを見て試してみましたがどうやってもWM_Mousewheel(マウスホイール)
を回したときに同期してくれません。
http://www.swissdelphicenter.ch/torry/showcode.php?id=1603

上記には2つの方法が書かれていますが、両方共に同じようにマウスホイールで
の同期ができませんでした。

どなたか2つのTStringGridのスクロールを同期させる方法をご存じの方いらっしゃ
いますでしょうか?

ご教授よろしくお願いします。

環境は
Windows7
Delphi2007
です。

--
Y.Hosoi


MLホームページ: http://www.freeml.com/delphi-users

----------------------------------------------------------------------
映画『シャッター アイランド』Tシャツプレゼント!
http://ad.freeml.com/cgi-bin/sa.cgi?id=fm9ND
-----------------------------------------------------[freeml by GMO]--

shika

unread,
Apr 8, 2010, 10:40:04 AM4/8/10
to delphi...@freeml.com
shikaと申します。

厳密にはスクロール同期じゃないですけど
こんなのはどうでしょーか。

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
SelectRows(StringGrid2, ARow);
end;

procedure TForm1.StringGrid2SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
SelectRows(StringGrid1, ARow);
end;

procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject);
begin
if StringGrid1.TopRow <> StringGrid2.TopRow then
StringGrid2.TopRow := StringGrid1.TopRow;
end;

procedure TForm1.StringGrid2TopLeftChanged(Sender: TObject);
begin
if StringGrid1.TopRow <> StringGrid2.TopRow then
StringGrid1.TopRow := StringGrid2.TopRow;
end;

procedure SelectRows(sg: TStringGrid; i: Integer);
var
gr:TGridRect;
begin
gr.Left := sg.FixedCols;
gr.Right := sg.ColCount - 1;
gr.Top := i;
gr.Bottom := i;
sg.Selection := gr;
end;

MLホームページ: http://www.freeml.com/delphi-users

----------------------------------------------------------------------
メールだけでみんなをMLにカンタン招待!
http://ad.freeml.com/cgi-bin/sa.cgi?id=fmCr9

sakai

unread,
Apr 8, 2010, 11:15:53 AM4/8/10
to delphi...@freeml.com
はじめまして、最近登録したsakaiといいます。
はじめて投稿します、よろしくお願いいたします。

閃きました。
正当なやりかたではないかもしれませんが、
もっとも簡単な方法ではないかと思います。

procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject);
begin
StringGrid2.TopRow := StringGrid1.TopRow;
//StringGrid2.LeftCol := StringGrid1.LeftCol; //必要なら利用
end;


MLホームページ: http://www.freeml.com/delphi-users

----------------------------------------------------------------------
サークルの新メンバーを便利な@招待機能で一気に登録しよう!
http://ad.freeml.com/cgi-bin/sa.cgi?id=fmCHp

hosoi

unread,
Apr 9, 2010, 5:37:50 AM4/9/10
to delphi...@freeml.com
細井です。

shika様、sakai様ありがとうございました。

|厳密にはスクロール同期じゃないですけど
|こんなのはどうでしょーか。
動作さえしっかりできれば問題ありません。

結果、shika様とsakai様の合わせ技で対応しました。

重ね重ねありがとうございました。

--
Y.Hosoi


MLホームページ: http://www.freeml.com/delphi-users

----------------------------------------------------------------------
メールだけでみんなをMLにカンタン招待!
http://ad.freeml.com/cgi-bin/sa.cgi?id=fmMMF

Reply all
Reply to author
Forward
0 new messages