DBGrid不支持鼠标的上下移动的解决代码

自己捕捉WM_MOUSEWHEEL消息处理
private
  OldGridWnd : TWndMethod;
procedure NewGridWnd (var Message : TMessage);
public

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
      DBGrid1.DataSource.DataSet.MoveBy(1)
    else
      DBGrid1.DataSource.DataSet.MoveBy(-1)
  end
  else
    OldGridWnd(Message);
end;

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

你可能感兴趣的:(grid)