Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi dbgrid continuous scrolling

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

like image 440
nikel Avatar asked Aug 02 '11 21:08

nikel


2 Answers

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.

like image 129
Sertac Akyuz Avatar answered Nov 15 '22 07:11

Sertac Akyuz


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;
like image 44
user3437976 Avatar answered Nov 15 '22 08:11

user3437976