Jump to content


Photo

MouseWheel scroll relative to datasource and scroll without focus


  • Please log in to reply
No replies to this topic

#1 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 18 September 2014 - 12:22 AM

I'd rather have a databound grid when unbuffered to scroll relative to the data rather than freely scrolling off into unused extents of the grid.
Here's how I implemented it in our custom control. This also answers another question I saw related to scrolling without focus.

procedure TMyDBGrid.WndProc(var message: TMessage);
var
MousePos: TPoint;
begin

if (Message.Msg = WM_MOUSEWHEEL) then
begin
MousePos.X := LoWord(Message.LParam);
MousePos.Y := HiWord(Message.LParam);

if PtInRect(self.ClientRect, self.ScreenToClient(MousePos)) then
begin
if (Message.WParam > 0) then
begin
// vertical scroll - up
if not DataSource.DataSet.Bof then
begin
DataSource.DataSet.Prior;
InvalidateCol(0);
end;
end
else
begin
// vertical scroll - down
if not DataSource.DataSet.Eof then
begin
DataSource.DataSet.Next;
InvalidateCol(0);
end;
end;
end;
end;
inherited;
end;




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users