Delphi 5 的 TDBGrid 無法支援滑鼠滾輪移動資掉指標,而且當有 PickList 的 Column 或是 Lookup Field 下拉時
滾動滑鼠滾輪會有很奇怪的行為。
要解決這個問題,可以繼承 TDBGrid 寫一個新的 DBGrid 類別,並覆寫兩個方法:
interface
type
TNewDBGrid = class(TDBGrid)
protected
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
end;
implementation
function TNewDBGrid.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(OnMouseWheelDown) then
OnMouseWheelDown(Self, Shift, MousePos, Result);
if (not Result) and (DataLink <> nil) and (DataLink.Active)
and (DataLink.DataSet <> nil) and (DataLink.DataSet.Active) then
begin
DataLink.DataSet.MoveBy(1);
Result := True;
end;
end;
function TNewDBGrid.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(OnMouseWheelDown) then
OnMouseWheelDown(Self, Shift, MousePos, Result);
if (not Result) and (DataLink <> nil) and (DataLink.Active)
and (DataLink.DataSet <> nil) and (DataLink.DataSet.Active) then
begin
DataLink.DataSet.MoveBy(-1);
Result := True;
end;
end;
沒有留言:
張貼留言