I’ve got a listbox where I am using the following code ( basically from the LR) to determine the row of the listbox based on the mouse position:
Function GetListboxRow(l as Listbox) As Integer Dim xValue As Integer xValue = System.MouseX - l.Left - Self.Left // Calculate current mouse position relative to top left of ListBox Dim yValue As Integer yValue = System.MouseY - l.Top - Self.Top // Calculate current mouse position relative to top of ListBox. // Add values for debugging purposes Dim smx, smy, lx, ly, sx, sy as integer smx = System.MouseX smy = System.MouseY lx = l.left ly = l.top sx = self.left sy = self.top Dim row As Integer row = l.RowFromXY(xValue, yValue) Return row End Function
What’s odd is that when I run this method after a normal mouse click, the row is calculated correctly. However, when running it when I do a contextual click, the System.MouseX and System.MouseY values are completely different.
So for example, if you do a contextual click in a cell, the cell click event first fires. In that event, I get the following values:
System.MouseX = 210
System.MouseY = 131
This gives me an xValue of 190 and a yValue of 66 in the function. And then when using listbox.RowFromXY(xValue,yValue), I get the right row value.
Now, once the cell click event fires, the ConstructContextualMenu event fires. In this event, I get the following values:
System.MouseX = 674
System.MouseY = 268
Completely different! Now I get an xValue of 654 and a yValue of 203. When using these values to calculate the row, I basically get a -1 as a row at those coordinates does not exist.
I know I can easily get the row value in the ConstructContextualMenu event as the local X and Y coordinates of the cursor are passed into the event. So this is more experimental than practical from a use perspective. But should it make a difference?
Why is the System.MouseX and System.MouseY values so different in the ConstructContextualMenu event? I would think they should be the same as in the CellClick event but as you can see - they are nowhere close…
This is in OS X by the way…