Hello Gousty,
Please read bellow, here is how mouse wheel work in components:
1) When you roll mouse wheel down once, OnMouseWheelDown event will trigger with Handled parameter. Default value for this parameter is False (as I have investigate in Controls.pas from Delphi VCL source).
2) Because by default, this parameter is False (hardcoded in Controls.pas), mouse wheel
will not work on Grid automatically. You need to set this Handled parameter to True manualy
inside event.
3) I have thinking about adding a property named HandleMouseWheel (Boolean), or similar to set
Handled to True by default, and save users with adding Handled := True inside event manually.
With following code all work fine, except that you need to add Handled := True in OnMouseWheelDown/Up events:
CODE
function TNxCustomGrid.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := inherited DoMouseWheelDown(Shift, MousePos);
if Result and not(gtEdit in GridState) then
begin
case (VertScrollBar.Max > 0) and not VertScrollBar.IsLast of
True: if ssCtrl in Shift then VertScrollBar.PageDown else VertScrollBar.Next;
else if (GridStyle = gsReport) and (HorzScrollBar.Max > 0)
then if ssCtrl in Shift then HorzScrollBar.PageDown else HorzScrollBar.Next;
end;
end;
end;
function TNxCustomGrid.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := inherited DoMouseWheelUp(Shift, MousePos);
if Result and not(gtEdit in GridState) then
begin
case VertScrollBar.Max > 0 of
True: if ssCtrl in Shift then VertScrollBar.PageUp else VertScrollBar.Prior;
else if (GridStyle = gsReport) and (HorzScrollBar.Max > 0)
then if ssCtrl in Shift then HorzScrollBar.PageUp else HorzScrollBar.Prior;
end;
end;
end;
Please tell me what you think.