{"id":529,"date":"2025-06-28T18:51:42","date_gmt":"2025-06-28T18:51:42","guid":{"rendered":"https:\/\/basicwebsitesolutions.com\/blog\/?p=529"},"modified":"2025-06-28T18:51:43","modified_gmt":"2025-06-28T18:51:43","slug":"delphi-6-using-scroll-in-a-dbgrid-with-wheelmouse-version-2-1-row-at-a-time-better","status":"publish","type":"post","link":"https:\/\/basicwebsitesolutions.com\/blog\/2025\/06\/28\/delphi-6-using-scroll-in-a-dbgrid-with-wheelmouse-version-2-1-row-at-a-time-better\/","title":{"rendered":"Delphi 6 : using scroll in a DBGrid with WheelMouse (version 2) 1 row at a time (better)"},"content":{"rendered":"\n<p>This one scrolls 1 row at a time<\/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>unit 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  Grid: TDBGrid;\nbegin\n  if WheelDelta = 0 then Exit;\n\n  Grid := TDBGrid(Sender);\n\n  if Assigned(Grid.DataSource) and Assigned(Grid.DataSource.DataSet) then\n    with Grid.DataSource.DataSet do\n    begin\n      if WheelDelta &lt; 0 then\n      begin\n        if not Eof then\n          Next;\n      end\n      else\n      begin\n        if not Bof then\n          Prior;\n      end;\n\n      \/\/ \ud83d\udc47 Force the grid to scroll to current record\n      if Assigned(Grid.SelectedField) then\n        Grid.SelectedField := Grid.SelectedField;\n    end;\n\n  Handled := True;\nend;\n\nend.<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This one scrolls 1 row at a time Enjoy Coffee Cup<\/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-529","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\/529","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=529"}],"version-history":[{"count":1,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts\/529\/revisions"}],"predecessor-version":[{"id":530,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts\/529\/revisions\/530"}],"wp:attachment":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}