Link to home
Start Free TrialLog in
Avatar of matsew
matsew

asked on

Mouse wheel in vb6 with DBGrid

I am just about out of my whits here now... having looked through tons of material and found that hooking up with MSGHOO32.ocx works just fine for most situations except when one of the DBGrid cells or rows has focus. At that point no messages comes through...

I need the wheel to work for scrolling up and down that grid no matter if the grid has the focus or not.

Anyone got any clues?
Avatar of carlsiy
carlsiy
Flag of Philippines image

There was a solution for this but in delphi...
http://delphi.about.com/cs/adptips2002/a/bltip1102_3.htm

happy hunting
Avatar of matsew
matsew

ASKER

The problem is not handling the event, but the fact that it seems not to fire the event as long as the grid has focus..... if I use the scrollbar to move the row that has focus out of sight (that it either is above or below the visible rows..... then scrolling the mouse fire the event but as soon as it does , the row that has focus moves back into sigth (since mousewheel down event shift one row down when scrolling down....) and then it doesn't receive any more events from the scroll wheel.
when you select the rows.... are you in edit mode or not?
Avatar of matsew

ASKER

What difference would that make?
There are only two columns that are editable. If I change a value in one column, and move that out of visibility (while the edit pencil is displaying in the grid) and then scroll, it fires the scroll just like it does otherwise.

If I take one of the samples that work with f.ex flexgrid, that scrolls fine, and I then place a blank grid with no settings with no nothing on (just to test) and put focus on one of the cells in the dbgrid, then it stops working again.

On the test I'm not doing anything but placing debug statements if the event is fired.
And yes , I have 10 years of experience working with VB so I know how to do basic stuff with it.
Avatar of matsew

ASKER

This code snippet might explain the problem better.

When the flexgrid has focus... the mousewheel operate as it should. Then you set focus to the dbgrid to the right by clicking in a cell, and then try to scroll the mouse. Then you see that the events are not firing anymore in the debug window.

hmmm...not allowed to attach a project here it seems...due to file extensions are not permitted on frm etc....
Avatar of matsew

ASKER

uploaded the sample to my webserver.

here is the link to the file:
http://www.websetup.net/scrol.zip
This is the normal behaviour of the mouse wheel, and not a problem with the subclassing method you're using, matsew. Try scrolling the file list in a standard explorer window when the address box has the focus... you can't! In fact there are many controls (TextBoxes, ListViews, TreeViews etc.) which will "steal" the scroll wheel's events. The way I've always dealt with this is to use the GetWindowRect API to confine wheel scrolling to the area directly over the grid/list I want to scroll. That way, if a user finds the scroll isn't working, it is a natural inclination to click in the grid/list and try again. It also has the added bonus that you can scroll multiple grids/lists on the same page/form.
Avatar of matsew

ASKER

That I would assume yes... that I would isolate the active control to only use scroll for that.
To check if it was actually the grid the mouse was hovering over.... but the problem here is that when the grid has focus, the scroll event doesn't get fired so I can not check what control is the current one...

The problem here is that I want this to work in the DBGrid, but when the DBGrid has the focus (or a single cell in it has the focus) I can not trap he scroll event to do the scrolling in the grid...?
That can not be the way it is supposed to be? , that the cells in the grid can't have focus but the mouse has to be hovering over it.... that would mean you would have a 100 page manual for the user to read to understand how to use the application....
The user would expect that when the grid or any cell in it has focus and he scroll the mouse, the current line would change.....
Avatar of matsew

ASKER

As to your comment on the explorer window... that is totally true that it does not scroll when address bare has focus, but it actually does scroll when the list has focus.

The idiotic problem here is that when the dbgrid has the focus (which actually is the list that should scroll) the mouse wheel events are not fired. At least not trappable in the samples I have found so far.
Basically, DBGrid doesn't handle Mouse Scroll Events (No MouseUp, MouseDown, MouseMove) a workaround here would be to instantiate a send key for arrow up or down, but still you cant detect the scroll movements once you are in focus of the DBGrid.
Avatar of matsew

ASKER

I think you are mistaken on that one. I have just verified that the grid support all three mousemove, mousedown and up events just fine, and that it does natively without any subclassing.

Arrow up and down also works fine for navigating up and down the grid, just not the scroll wheel.
opps reverified it.. my bad.
ASKER CERTIFIED SOLUTION
Avatar of Antagony1960
Antagony1960

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matsew

ASKER

Excellent!!!!
You were right on the spot with this one.
You saved my day totally with this one.... (actully way more than my day....)
Thanks a lot to all for their attention to this issue.
Glad to have helped. :-)