7

I'm making an application that holds orders and prints invoices. I have some labels, tedits, tmemos, buttons, a datasource, an adotable, a popupmenu, and a dbgrid on my form.

When I build the program and scroll down the dbgrid scrollbar, it scrolls after I release mouse button. But i want continuous scrolling.

Greetings

nikel
  • 653
  • 4
  • 13
  • 24

2 Answers2

12

That's called thumb tracking. Derive a new class to override scrolling behavior. Example of using an interposer class:

type
  TDBGrid = class(DBGrids.TDBGrid)
  private
    procedure WmVScroll(var Message: TWMVScroll); message WM_VSCROLL;
  end;

  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    ..

implementation

procedure TDBGrid.WmVScroll(var Message: TWMVScroll);
begin
  if Message.ScrollCode = SB_THUMBTRACK then
    Message.ScrollCode := SB_THUMBPOSITION;
  inherited;
end;


You can also replace the WindowProc of the control if you don't want to derive a new class. All you need to do is to handle WM_VSCROLL message. Here is an example how to do that.

Community
  • 1
  • 1
Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
3

Here is the other solution Sertac Akyuz mentioned without having to derive a new class from TDBGrid:

  private
    FOrgDBGridWndProc: TWndMethod;
    procedure DBGridWndProc(var Msg: TMessage);
  // ...
  end;

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

procedure TForm1.DBGridWndProc(var Msg: TMessage);
begin
  if (Msg.Msg = WM_VSCROLL) and
    (LongRec(Msg.wParam).Lo = SB_THUMBTRACK) then
  begin
      LongRec(Msg.wParam).Lo := SB_THUMBPOSITION;
  end;
  if Assigned(FOrgDBGridWndProc) then
    FOrgDBGridWndProc(Msg);
end;
user3437976
  • 101
  • 1
  • 6