Ticket Q276698
Visible to All Users

How to scroll unbound cxGrid with mousewheel when grid is unfocused

created 15 years ago

Hello, thank you for looking at this for me.
Here's my overall goal: Give the user a popup window from which they can select a City, State, Zip combination (records loaded from the DB into an unbound cxGrid).
The popup is displayed from a TcxButtonEdit containing a single "Down" button. The popup is displayed if the user clicks the "Down" button, of if they start typing within the text area of the TcxButtonEdit control.
It's important to note that the user must be able to enter a City, State, or Zip (depending on what's currently being selected) that does not exist in the grid.
When the popup is displayed due to the user typing, the popup does not receive focus. Instead, the TcxButtonEdit control retains focus (so that the user can continue to type text). Since the grid is unfocused, I use the following to perform incremental searching:
View.OptionsSelection.CellSelect := False;
View.Controller.IncSearchingText := text from TcxButtonEdit
View.OptionsBehavior.IncSearchItem := the grid column in the TcxGrid
If the user clicks the grid, I change the above to:
View.OptionsSelection.CellSelect := True;
View.Controller.IncSearchingText := '';
View.OptionsBehavior.IncSearchItem := nil;
When the grid has focus, there's no problem using the mouse wheel (obviously). However, I would like to be able to scroll the grid records programmatically when I detect WM_MOUSEWHEEL or CM_MOUSEWHEEL messages. I'm able to intercept these messages within the form that hosts the TcxButtonEdit control (TForm1 below). For example, using a TApplicationEvents component:
procedure TForm1.ApplicationEventsMessage(var AMsg: tagMSG; var AHandled: Boolean);
begin
  case AMsg.Message of
    WM_MOUSEWHEEL:
      if not View.Site.Focused then
        if FindVCLWindow(AMsg.Pt) = View.Site then
        begin
          View.Site.Perform(CM_MOUSEWHEEL, AMsg.WParam, AMsg.LParam);
          AHandled := True;
        end;
  end;
end;
This approach works fine for other controls on TForm1 (like a calendar) that are unfocused.
Above, I'm using View.Site because FindVCLWindow(AMsg.Pt) returns a TcxGridSite instance. I've tried sending CM_MOUSEWHEEL & WM_MOUSEWHEEL to the grid (Grid.Handle) as well with no luck.
Additionally, I've tried using SetCapture(Grid.Handle) and SetCapture(View.Site.Handle) before calling Perform(XX_MOUSEWHEEL, AMsg.WParam, AMsg.LParam);
You may ask me, "Why didn't you just use a TcxLookupComboBox?" I did, but I could not find a way to let the user enter text that was *not* in the ListSource.
Thank You in advance for your Help,
John

Answers approved by DevExpress Support

created 15 years ago (modified 11 years ago)

Hello John.
Thank you for your message. You should call the TcxGridSite's Scroll method to perform scrolling. Attached is an example that shows how to perform this task. Does this solution meet your requirements?
Best regards,
Ingvar.

    Comments (1)
    DevExpress Support Team 15 years ago

      Hello John.
      Thank you for informing us that the problem is now resolved. I'm glad to hear that my assistance was helpful.
      Please feel free to contact us if you have any questions regarding our controls. We'll do our best to find a solution for you.
      Best regards,
      Ingvar.

      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.