Monday, May 26, 2008

Solved problem: delphi dbGrid won't/doesn't scroll record position - jologs!

This is the best solution of all. Others are either not functioning, have logical errors, or too complex. This is the most simple:
-----------------------------------------------

unit Unit1

interface

uses
DBGrids, Db, Controls, Windows, Messages,

type
NewControl = class(TControl);

...

private
procedure DBGridScroll(var Message: TMessage);
{ Private declarations }
public
{ Public declarations }

...

procedure TForm1.DBGridScroll(var Message: TMessage);
var
count : short;
begin
if (Message.Msg = WM_MOUSEWHEEL) then begin
count:=HIWORD(Message.WParam);
count:=count div 120;
DBGrid1.DataSource.DataSet.MoveBy(-count)
end else NewControl(DBGrid1).WndProc(Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DBGrid1.WindowProc := DBGridScroll;
end;

No comments: