Detecting Right Mouse Button Event

I have a VSFlexGrid which when the user clicks the right mouse button brings up a pop-up menu.  I need to know what column the user was in when they performed the mouse click but the right mouse button event does not cause a click event in the grid.  I need to know either a) how to generate the event by using the right mouse button or b) simulate a left mouse button click to fire up the event.
JEGBAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MarktalbotCommented:
if there is a mouse down event then there is a variable passed that tells you which button has been pressed.
0
VbmasterCommented:
Sub Grid1_MouseDown (Button As Integer, X As Single, Y As Single..)

   If (Button = vbRightButton) Then
      'Show the popupmenu here
   End If

End Sub
0
JEGBAuthor Commented:
To clarify:  If you click the Left Mouse button in a VSFlexGrid the Row and Col properties change to the new cell (row and col) properties that the mouse cursor is in when the event occurred.  However if you click the right mouse button in a cell you can detect the event BUT the col and row properties do not change but instead remain what they were before the event.  I need to know a way of detecting what column the mouse is in when the right mouse button event occurs.
0
JEGBAuthor Commented:
I have this Q answered on another Question I've posted, basically you use the MouseRow and MouseCol properties, which I must have missed while scanning the help.
0
pmwoodCommented:
If the grid does not support a right-click event, you will have to subclass the control window using the Windows API to know when it happens.

Use the SetWindowLong(lhWnd, GWL_WNDPROC, AddressOf WindProc)API call with VSgrid.hWnd property to redirect window messages to a custom procedure, WindProc.

Within WindProc, trap the WM_RBUTTONDOWN message and call a procedure to do what you want on the right-button-click.  You MUST PASS all other window messages to the default window event handler.

Set the message handler back to the default BEFORE unloading the form with the control on it.

Examples of the use of SetWindowLong/WindProc can be found on MSDN or the MS web site knowledge base - to much to include here, but you will need them.

NB.  The VB IDE is v. sensitive to this API, and may crash during debugging.  I use a conditional compilation argument to avoid this when working on other parts of my code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.