Delphi dbgrid continuous scrolling

nikel picture nikel · Aug 2, 2011 · Viewed 7.5k times · Source

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

Answer

Sertac Akyuz picture Sertac Akyuz · Aug 2, 2011

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.