TListView - mouse wheel only if focused lazarus / 31-LCL ---------------------------------------------------------------------- thbu · 2020-04-03 23:30 Hi, I have a TListView inside a TScrollBox. When I'm using the mouse wheel to scroll the TScrollBox, scrolling will stop as soon as the mouse cursor is over the TListView. Is there a way to prevent the TListView from "stealing" the mouse wheel? Ideally in the way that I can still scroll inside the TListView after I click it (make it focused)? Thanks for any suggestions. ---------------------------------------------------------------------- jamie · 2020-04-04 01:27 The OnMouseWheel event has a HANDLED value you can set to TRUE;  This may stop that effect and pass the messages to the background control, not sure but I think you could redirect the message effects to the parent control when handling this...  You can experiment on that a bit..  Most likely if you set it via to what ever the control state it , for example focused..  handled := Not Focused; etc.. ---------------------------------------------------------------------- jamie · 2020-04-04 02:19 Ok, I found out how you can do it easy...  Disable the listview while you are not in it..  Enable := False;  This will pass all mouse messages through it to the scrollbox  when you click on it, it will actually go to the scroll box but this is where you can then determine to enable it again by testing the area of the scroll box you clicked to see if the list view lives there.   when you move your mouse outside the list box the OnExit can be used to disable it again...  of course every time you do this you will need to click twice to re- enable the Listview …  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ScrollBox1MouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  ListView1.Enabled :=  PtInRect(ListView1.BoundsRect,Point(X,Y));end;  procedure TForm1.ListView1Exit(Sender: TObject);begin  ListView1.Enabled := False;end; ---------------------------------------------------------------------- thbu · 2020-04-04 08:30 Thank you very much jamie for this suggestion. It has a few issues: - as you pointed out you have to click twice to get into the ListView - the items in the ListView are drawn with gray background when it is disabled. Can this be changed easily without painting the items myself? - PtInRect(ListView1.BoundsRect,Point(X,Y)) must be shifted if the ScrollBox is scrolled down. It can be solved, but I'd be happy to hear if there are other ways to tackle the issue more directly. ---------------------------------------------------------------------- wp · 2020-04-04 09:33 Why do you put a ListView into a ScrollBox after all? A ScrollBox is a viewport to an arrangement of controls which cover a larger area than is directly seen; it provides scrollbars to get access to the hidden controls. But a ListView has scrollbars of its own. I don't see a reason why it should be inside a ScrollBox. ---------------------------------------------------------------------- thbu · 2020-04-04 11:33 There are other things inside the ScrollBox. ---------------------------------------------------------------------- jamie · 2020-04-04 13:23 I believe you would need to override the WM_MOUSEWHEEL message via  Window Procedure Hook of the ListView. ---------------------------------------------------------------------- jamie · 2020-04-04 14:08 I don't understand something here.. All I need to do is ensure the ListView does not have a focus and it already does pass all the mouse messages to the parent..  Just Ensure the ListView.Focused := False; and when you click on it , it then becomes focused and thus starts accepting the scroll wheel...  I think your issue you need to move the focus to the scrollbox or somewhere else.  Because with me If I have the ListView un-focused it works as you wish.. Let me retract that a bit, it seems I am getting some random behavior over here. I'll post back ---------------------------------------------------------------------- jamie · 2020-04-04 14:54 This seems to work... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListView1MouseWheel(Sender: TObject; Shift: TShiftState;  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);Const Busy:Boolean = False;  Var    OldState:Boolean;begin  Handled := Not TListView(Sender).Focused;  If Handled then  Begin  Beep;   OldState := TListview(Sender).Enabled;   TListView(Sender).Enabled := False;   MousePos := TListView(Sender).ClientToScreen(MousePos);   SendMessage (TListview(Sender).parent.handle,WM_MOUSEWHEEL,MakeLong(0,WheelDelta),  MakeLong(MousePos.X,MousePos.Y));   TListView(Sender).Enabled := OldState;  End;end;                             But you still need to move the focus elsewhere because it will ignore this of course if the listview gets focused. ---------------------------------------------------------------------- thbu · 2020-04-06 00:49 Quote from: jamie on April 04, 2020, 04:54:24 pmThis seems to work... Thank you jamie! It does indeed work and solves my problem.