Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi DBGrid滚动页面而不是行_Delphi_Vcl_Dbgrid - Fatal编程技术网

Delphi DBGrid滚动页面而不是行

Delphi DBGrid滚动页面而不是行,delphi,vcl,dbgrid,Delphi,Vcl,Dbgrid,我对DBGrid垂直滚动有一个问题。当我使用鼠标滚轮或垂直滚动条垂直滚动它时,它会上下移动所选行。我想让它滚动不是选定的行,而是整个网格。就像它在MicrosoftExcel中工作一样(只是让你知道我的意思)。有什么建议吗?我认为这是不可能的,因为在我看来,DBGrids上的滚动条更像是一个进度指示器,而不是一个滚动条。它的行为与ListView中滚动“页面”的滚动不同,在db控件中,即使您向上或向下移动一行,滚动条也会改变以反映“当前行”/“总行”分数,这几乎是我想要看到的。在swissdel

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

我认为这是不可能的,因为在我看来,DBGrids上的滚动条更像是一个进度指示器,而不是一个滚动条。它的行为与ListView中滚动“页面”的滚动不同,在db控件中,即使您向上或向下移动一行,滚动条也会改变以反映“当前行”/“总行”分数,这几乎是我想要看到的。在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.

这段代码实际上滚动所选行,但它不会停在页面底部,让您滚动到网格的最底部。