My goal was to display a context-sensitive menu in response to a right-click on a treeview node, but I had a lot of problems getting there.
Initially, I put code in the MouseDown() event, because that has automatic access to which button was clicked. When the event fires, it receives four parameters, the first of which is 1 for the left mouse button or 2 for the right mouse button.
Unfortunately, at that moment, the tree's SelectedItem property still referred to the previously selected node, not the one on which I was right-clicking.
I had heard that the MouseUp() event was the correct one for detecting a right-click action, and indeed, it has the same four parameters as MouseDown(), so I moved my code into that method. But now the event didn't fire, and my code didn't run at all. I put WAIT WINDOW commands in the MouseUp() and MouseDown() events to try to figure out where things were failing, and suddenly things started working; I now got the correct node with a right-click. When I removed all my debugging statements, leaving only code in the MouseUp() as before, the event once again failed to fire.
From my trials, it seems that MouseUp() only fires if there's some code in the MouseDown() event. This is the working solution I came up with:
* MouseDown event
LPARAMETERS nButton, nShift, nXCoord, nYCoord
Dummy = 0
* MouseUp event
LPARAMETERS nButton, nShift, nXCoord, nYCoord
ClickedKey = this.SelectedItem.Key
DO CASE
CASE nButton = 1 && Left Click
** processing steps>
CASE nButton = 2 && Right Click
DO RightClickMenu.mpr
ENDCASE
I don't use the NodeClick event anymore, all mouse click-coding happens in the MouseUp() event.