Ticket Q538627
Visible to All Users

How to redirect mouse wheel message to a cxGrid

created 11 years ago

Hello,I'm trying to redirect mouse wheel message to controls in order to allow scroll without clicking on them (You just need to move mouse on control that you want to scroll).It works good with TcxRichEdit but I'm encountering some problems with TcxGrid.
I've attached a complete sample that you can test. There's also an image inside zip archive with all you need to do in order to recreate the issue (step by step).Furthermore, sample project contains a "debug TcxRichEdit" where you can send messages by using "DebugMessage" method.Please ask if you need other informations.Thanks to everyone.

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,
I believe a similar question has been already discussed in our Support Center. Please refer to the Q276698: How to scroll unbound cxGrid with mousewheel when grid is unfocused ticket for the information.

    Show previous comments (5)
    DevExpress Support Team 10 years ago

      Hello Poul,

      To process your recent post more efficiently, I created a separate ticket on your behalf: T195976: How to redirect mouse wheel message to a cxGrid with VCL 14.2. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

        Here's how I solved this problem.  I dropped an ApplicationEvents control on my main form and then hooked the OnMessage event as follows:

        Delphi
        procedure TMainForm.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); var  mousePos  : TPoint;  wc        : TWinControl;  AGridSite : TCxGridSite; begin  //mouse wheel scrolling for the control under the mouse  if Msg.Message = WM_MOUSEWHEEL then  begin    mousePos.x := Word(Msg.LParam);    mousePos.y := HiWord(Msg.LParam);    wc         := FindVCLWindow(mousePos);    if wc = nil then    begin      Handled := False;    end    else      if wc is TCxGridSite then      begin        AGridSite := wc as TCxGridSite;        if (AGridSite.GridView.ClassType = TcxGridDBTableView) or           (AGridSite.GridView.ClassType = TcxGridTableView) then        begin          if Msg.WParam > 0 then            AGridSite.GridView.Site.ScrollContent(dirUp)          else            AGridSite.GridView.Site.ScrollContent(dirDown);          Handled := true;        end      end      else      begin        if wc.handle <> Msg.hwnd then        begin          SendMessage(wc.handle, WM_MOUSEWHEEL, Msg.WParam, Msg.LParam);          Handled := true;        end;       end;   end; end;

        This allows my unfocused cxGrid and cxDBGrids to scroll when the mouse is over them.
        YMMV.

          I should have noted that I'm using Delphi XE and 14.2.2 and this has worked with all releases of DevExpress.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.