{"id":479,"date":"2023-06-06T17:28:18","date_gmt":"2023-06-06T17:28:18","guid":{"rendered":"http:\/\/basicwebsitesolutions.com\/blog\/?p=479"},"modified":"2023-06-06T17:33:06","modified_gmt":"2023-06-06T17:33:06","slug":"delphi-6-using-scroll-in-a-dbgrid-with-wheelmouse","status":"publish","type":"post","link":"https:\/\/basicwebsitesolutions.com\/blog\/2023\/06\/06\/delphi-6-using-scroll-in-a-dbgrid-with-wheelmouse\/","title":{"rendered":"Delphi 6 : using scroll in a DBGrid with WheelMouse"},"content":{"rendered":"\n<p>There was  a request to make the mouse wheel as the scrolling. I found the code and wanted to save it as well here.<\/p>\n\n\n\n<p>Enjoy <\/p>\n\n\n\n<p>Coffee Cup<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/with delphi7\n\nunit Unit1;\n\ninterface\n\nuses\n  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,\n  Dialogs, Grids, DBGrids, DB, DBTables;\n\ntype\n  TForm1 = class(TForm)\n    DataSource1: TDataSource;\n    Table1: TTable;\n    DBGrid1: TDBGrid;\n    procedure FormCreate(Sender: TObject);\n    procedure DBGridMouseWheel(Sender: TObject; Shift: TShiftState;\n      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);\n  private\n    { Private declarations }\n  public\n    { Public declarations }\n  end;\n\n  TWheelDBGrid = class(TDBGrid)\n  public\n    property OnMouseWheel;\n  end;\n\nvar\n  Form1: TForm1;\n\nimplementation\n\n{$R *.dfm}\n\nprocedure TForm1.FormCreate(Sender: TObject);\nbegin\n  TWheelDBGrid(DBGrid1).OnMouseWheel := DBGridMouseWheel;\nend;\n\nfunction GetNumScrollLines: Integer;\nbegin\n  SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, @Result, 0);\nend;\n\nprocedure TForm1.DBGridMouseWheel(Sender: TObject; Shift: TShiftState;\n  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);\nvar\n  Direction: Shortint;\nbegin\n  Direction := 1;\n  if WheelDelta = 0 then\n    Exit\n  else if WheelDelta &gt; 0 then\n    Direction := -1;\n\n  with TDBGrid(Sender) do\n  begin\n    if Assigned(DataSource) and Assigned(DataSource.DataSet) then\n      DataSource.DataSet.MoveBy(Direction * GetNumScrollLines);\n    Invalidate;\n  end;\nend;\n\nend.\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/www.swissdelphicenter.ch\/en\/showcode.php?id=2142\">https:\/\/www.swissdelphicenter.ch\/en\/showcode.php?id=2142<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There was a request to make the mouse wheel as the scrolling. I found the code and wanted to save it as well here. Enjoy Coffee Cup https:\/\/www.swissdelphicenter.ch\/en\/showcode.php?id=2142<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3,1],"tags":[302,301,300,299],"class_list":["post-479","post","type-post","status-publish","format-standard","hentry","category-day-to-day-life","category-delphi-and-interbase","category-life-as-a-programmer","tag-dbgrid","tag-delphi-6","tag-mousewheel","tag-scroll"],"_links":{"self":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts\/479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=479"}],"version-history":[{"count":2,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts\/479\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts\/479\/revisions\/481"}],"wp:attachment":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}