如何使DBGrid控件支持鼠标滚轮!我用的Delphi 6, 可有比较简单的方法??
我刚开始用Delphi6,可否请各位说详细一些!!多谢了!~

解决方案 »

  1.   

    我自己做了一个非可视的控件,它会自动帮你的DBGRID自动处理鼠标滚轮。
      

  2.   

    继承 DBGrid,然后public 了他的DoMouseWheel
    在你的代码里面有一个Type
       Frmxxxx= class(TForm)的行,
    在他的上面加上这么一段
    type
      TDBGrid= class(DBCGrids.TDBGrid)   
      public
        function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
      end;Type
      ..... 你原来的程序段
    并且在 implementation 段里面写上
    function TDBGrid.DoMouseWheel(Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint): Boolean;
    begin
      if WheelDelta > 0 then
        Datasource.DataSet.Next;
      if wheelDelta < 0 then
        DataSource.DataSet.Prior;
    end;
      

  3.   

    to pazee(耙子):你的方法好像不太好用
    [Error] DBGridwh.pas(16): Undeclared identifier: 'TPoint'
    。。
    。。
    。。
    [Error] DBGridwh.pas(15): Unsatisfied forward or external declaration: 'TDBGridwh.DoMouseWheel'
    [Fatal Error] dclusr.dpk(38): Could not compile used unit 'DBGridwh.pas'能不能吧你的方法说的细致一点
      

  4.   

    谢谢!我测试,通过了!为各位研究,我把我做的一测试例程代码公布如下:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, DBCtrls, Grids, DBGrids, DB, ADODB, MyDbGrid;
    type
      TDBGrid= class(DBGrids.TDBGrid)
      public
        function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
      end;
    type
      TForm1 = class(TForm)
        ADOConnection1: TADOConnection;
        ADODataSet1: TADODataSet;
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        DBNavigator1: TDBNavigator;
        ADOQuery1: TADOQuery;
        DataSource2: TDataSource;
        ADOTable1: TADOTable;
      private
        { Private declarations }
      public    { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}function TDBGrid.DoMouseWheel(Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint): Boolean;
    begin
      if WheelDelta < 0 then
        Datasource.DataSet.Next;
      if wheelDelta > 0 then
        DataSource.DataSet.Prior;
    end;end.
    我想此帖该结了!