gpt4 book ai didi

delphi - DBGrid 滚动页面而不是行

转载 作者:行者123 更新时间:2023-12-03 18:52:02 26 4
gpt4 key购买 nike

好吧,我对 DBGrid 垂直滚动有疑问。当我用鼠标滚轮或垂直滚动​​条垂直滚动它时,它会上下移动选定的行。我想让它滚动的不是选定的行,而是整个网格。就像它在 Microsoft Excel 中工作一样(只是为了让你知道我的意思)。有什么建议么?

最佳答案

嗯,几乎是我想看到的。在 swissdelhicenter.ch 上找到了 hanuleye 的帖子。此代码让您可以使用鼠标滚轮自由滚动 DBGrid。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables;

type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
DBGrid1: TDBGrid;
procedure FormCreate(Sender: TObject);
procedure DBGridMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

TWheelDBGrid = class(TDBGrid)
public
property OnMouseWheel;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
TWheelDBGrid(DBGrid1).OnMouseWheel := DBGridMouseWheel;
end;

function GetNumScrollLines: Integer;
begin
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, @Result, 0);
end;

procedure TForm1.DBGridMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var
Direction: Shortint;
begin
Direction := 1;
if WheelDelta = 0 then
Exit
else if WheelDelta > 0 then
Direction := -1;

with TDBGrid(Sender) do
begin
if Assigned(DataSource) and Assigned(DataSource.DataSet) then
DataSource.DataSet.MoveBy(Direction * GetNumScrollLines);
Invalidate;
end;
end;

end.

关于delphi - DBGrid 滚动页面而不是行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1251065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com