Delphi DbGrid鼠标滚屏

Delphi的DbGrid默认不支持滚屏。通过一下代码可以让DbGrid支持鼠标滚屏

 

procedure NewGridWnd(var message:TMessage); 

 

OldGridWnd: TWndMethod;

 

procedure TForm1.FormCreate(Sender: TObject);
begin
  
  //支持鼠标滚动
  OldGridWnd :=dbgrd.WindowProc;
  dbgrd.WindowProc :=NewGridWnd;
end;
//支持鼠标滚动
procedure TForm1.NewGridWnd(var message:TMessage);
var
  IsNeg: Boolean;
begin
  if message.Msg = WM_MOUSEWHEEL then
    begin
      IsNeg :=Short(message.WParamHi)<0;
      if IsNeg then
        dbgrd.DataSource.DataSet.MoveBy(1)
      else
        dbgrd.DataSource.DataSet.MoveBy(-1)
    end
  else
    OldGridWnd(message);
end;
 

你可能感兴趣的:(Delphi)