[RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
I'm using a flexgrid to show some data from my database.
So there's a problem i can't scroll down my flexgrid with the mouse i have to click on the scroll down bar. there's another way to do this using the mouse to scroll down to the last item contained in my flexgrid a not use the scroll down bar.
Last edited by orozcore; Feb 17th, 2006 at 09:19 PM.
I have tested the code in my programm and works fine.
but there's something i see
I have to copy and paste the procedure MouseWheel in each Form i have, because i have at least 15 forms with a flexgrid so maybe i can put that in my module
I have made some changes to the example code you sent me bushmobile
The problem is that in some forms I have two MSFlexGrid's and the hook only worked with one, because the flexgrid is only in the Form and the MouseWheel uses MSlexGrid1 but in this case i have more than one FlexGrid, and not exactly named MSFlexGrid1
So i did this changes to improve your code:
- Put the MouseWheel in the Module bas including another variable as parameter MyGrid as MSFlexGrid, to change the control to make the mousewheel changes
- Create a variable in my module, MyGrid as MSFlexGrid
- Add a parameter in the WheelHook of my PassedFlexGrid and set my variable MyGrid to this control passed
- Modify the WindowProc procedure to call mousewheel from my module and set the variable MyGrid in MouseWheel procedure.
-To call WheelHook i do it when in the Events MSFlexGrid_Click and MSFlexGrid_GotFocus like this
VB Code:
Private Sub MSFlexGrid1_Click()
WheelUnHook
WheelHook Me, MSFlexGrid1
End Sub
Private Sub MSFlexGrid1_GotFocus()
WheelUnHook
WheelHook Me, MSFlexGrid1
End Sub
and Unhook when the Control LostFocus
VB Code:
Private Sub MSFlexGrid1_LostFocus()
WheelUnHook
End Sub
you can check the changes in the uploaded zip file
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
Thanks so much. I've had complaints from some of my clients about this very problem - I've always downplayed them and told them to find better drivers.
This is a much nicer solution - I will try to implement it!
Thanks again!
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
This is a great solution, I only have two 'bad' comments.
The first is that the step is a bit too large - as it doesn't take into account Fixed rows, partially-visible rows, or scrollbars. That is easy to fix using the .RowIsVisible method in the FlexGridScroll sub like this:
VB Code:
Lstep = Int(Lstep)
Do While Not (.RowIsVisible(.TopRow + Lstep))
Lstep = Lstep - 1
Loop
(admittely I personally prefer smaller steps, say Lstep = 3)
The second issue is that the grid doesn't scroll the grid that the mouse is over (which is how it normally works), only the active one. To 'correct' this I guess that the MouseWheel sub would need to check the mouse co-ordinates, and see if a grid is underneath.
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
si - having not really reviewed the code yet - could't the hook change from grid to grid based on the grid's MOUSEMOVE event? Or do you think that is too expensive?
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
yeah, i was aware of both of those. i was just showing that that code could be used with multiple things (and was feeling a bit too lazy to add the checking which one it's over stuff )
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
Fair enough, good work tho - I'll be using a modified version of it
Originally Posted by szlamany
si - having not really reviewed the code yet - could't the hook change from grid to grid based on the grid's MOUSEMOVE event? Or do you think that is too expensive?
That would be possible, but you'd need to use the mousemove events of all controls (and the form) to ensure that the appropriate control is used. Without having tested yet, I personally think an API check of the mouse position (when a scroll event takes place) would be more apt.
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
Originally Posted by szlamany
si - having not really reviewed the code yet - could't the hook change from grid to grid based on the grid's MOUSEMOVE event? Or do you think that is too expensive?
Oh - I see the difference you mean...
Wheel should only scroll a grid if it's over a grid.
If the mouse moves off the grid the wheel should do nothing...
Or I could also see the argument for saying that the last "grid" hovered over can retain wheel scroll power - regardless of if the mouse leaves the grid...
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
Originally Posted by si_the_geek
Fair enough, good work tho - I'll be using a modified version of it
That would be possible, but you'd need to use the mousemove events of all controls (and the form) to ensure that the appropriate control is used. Without having tested yet, I personally think an API check of the mouse position (when a scroll event takes place) would be more apt.
That's right...
I can see that the mouse wheel works right now if a combo box on my form has focus - so I'd be stealing the "mouse moves" from that combo box if the mouse is over the grid...
I guess I'll have to start testing this and see where it gets me.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
Actually I've just done a quick test with a combo and list, it seems that they also have the same behaviour - it is the active control that scrolls, no matter where the mouse is.
It's strange considering that Outlook etc don't work that way, but it means that the code above (with adjustments for the scroll amount) is spot on.
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
ok, i've added in your adjustment from post #15, si, and I've added an IsOver function so it scrolls the grid it's over rather than the one with focus.
Edit: Better version now available in the CodeBank
Last edited by bushmobile; Feb 23rd, 2006 at 10:21 PM.
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
I said that i had resolved my problem, buy maybe it wasn't true because when i use MouseWheel sub worked for all of my FlesGrids only one didn't work so I check again and download WheelHook3.zip from bushmobile where i can scroll the flexgrid when the mouse pointer is over so this resolved my problem.
So now i can scroll all the flexgrids of my programm and there's no problem
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
Originally Posted by bushmobile
ok, i've added in your adjustment from post #15, si, and I've added an IsOver function so it scrolls the grid it's over rather than the one with focus.
Bushmobile - I tried the version the the codebank - wheelhook3.zip.
I added to your test project a combobox. As long as the combobox does not have focus, the wheel scrolls whatever flexgrid you are over.
If the combobox gets focus, then the wheel on scrolls the combobox - regardless of what you hover over.
Do you think this can easily be overcome? Or am I stuck using the "click" to focus on flexgrid version?
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
just things are named differently and i've used a collection to store the lPrevProc values.
before we integrate your code into mine (or visa versa), why are you subclassing the WM_ACTIVATEAPP message, and not just using the Form_Activate event?
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
Originally Posted by bushmobile
before we integrate your code into mine (or visa versa), why are you subclassing the WM_ACTIVATEAPP message, and not just using the Form_Activate event?
Form_Activate does not fire when your app is left and/or returned to.
WM_ACTIVATEAPP message does fire.
We do it to make sure the "control" we desire the focus to be on still has the focus.
I think the snippet I posted:
Code:
'Let the window process messages as well
WndProc = CallWindowProc(m_lPrevProc, hwnd, wMsg, wParam, lParam)
indicates that this CallWindowProc passes the message back along to the windows processes.
Maybe not calling this function can suppress the drop-down type controls from grabbing the mouse wheel without have to hook and unhook it in all those places.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
ok, i've got rid of the need for those fiddly _DropDown, _LostFocus things by using CB_DROPDOWNSTATE, to check if it's dropdown. I've updated the zip in the codebank.
you should be able to just add a case in like the below so you can implement your WM_ACTIVATEAPP code.
VB Code:
Case WM_ACTIVATEAPP
Set fFrm = GetForm(Lwnd)
If Not fFrm Is Nothing Then Call fFrm.AppFocus(CBool(wParam))
regarding the CallWindowProc stuff in the WheelHook4.zip, the
line (or whatever equivalent you wish to use) needs to be after the monitoring of the messages, because sometimes we don't want to process the message, just discard it (in the case of the combobox being selected, but the mouse not on it.)
There are of course alternative ways to do what I've done. I'm using the vbAccelerator SSubTmr to manage subclassing in my current project.
Last edited by bushmobile; Feb 19th, 2006 at 04:05 PM.
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
I've actually got a bit of testing and modification to go through here...
That WM_ACTIVATEAPP is being listened to by the MDI-parent form of my app.
I really want this WM_MOUSEWHEEL to be caught by whatever childform has focus.
So I'm off to experimenting with having two WINDOWPROC functions in my app - one for the parent-window and another for this child window/mouse wheel stuff.
But thanks again for this - it's really going to make many of my more sophisticated users happy.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
It is working for me now. I'm still hooking the parent form so I can listen for WM_ACTIVATEAPP.
And I am changing the mousewheel hook based on what child form has focus. If I alt-tab back and forth from child to child the mousewheel action is perfect.
I haven't yet decided how to make it pick the grid to scroll. I do a lot of "hiding" grids by putting them behind other grids - got radio-buttons that make grids full-size or restore-to-original. On forms with several grids I'm starting to think that whenever the user mouses-over a grid that becomes the "wheel grid" - even if they do not stay on the grid (like move slightly off the grid so as to see the data, you know how the mouse and tool-tip can get in the way sometimes).
I'm so excited I'm going to have to add a "new feature" pop-up window to my app so my customers know this one got enhanced.
edit: btw - why are you not simply scrolling it one row up or down in your samples?
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
So I'm off to experimenting with having two WINDOWPROC functions in my app - one for the parent-window and another for this child window/mouse wheel stuff.
Messing around with it is the best way to learn
btw - why are you not simply scrolling it one row up or down in your samples?
cos that's just how it was on the website i got the original code from.
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
Didn't know about that...
We always use:
Code:
On Error Resume Next
Debug.Print 1 / 0
gDebugMode = (Err.Number <> 0)
btw - your change about .Rows makes sense...
but in the long run this is a perfect time to ignore all errors in the routine - we simply don't want to stop with any error that might pop-up when using the wheel.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel
We already had tons of events already tracking grid selection and even grid hover (we set the tooltip text to the full "cell value" - if it's not fully displayed - when you hover over a cell).
So I ended up setting a form-level variable with the "grid" to be "mouse-wheel" associated.
Clicking into a grid sets that grid as the mouse-wheel grid. Hovering into it does the same. But hovering out does not change the setting.
And this was the simple function we used to move up/down
VB Code:
Public Function ScrollGrid(f As Form, lngMouseKeys As Long, lngXP As Long, lngYP As Long, lngRotation As Long) As Boolean