The code below comes from a working project and do not works in another project (returns )1 for both Row, Cell):
[code] Dim Click_Row As Integer // The Selected Row #
Dim Click_Cell As Integer // The Selected Cell #
// What is the selected Row / Column (Clicked Row/Cell ?)
Click_Row = Me.RowFromXY( System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top)
Click_Cell = Me.ColumnFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top)
If Click_Row = -1 Or Click_Cell = -1 Then
MsgBox “Erreur dans ContextualMenuAction
ClickRow = -1 Or ClickColumn = -1”
No container control
run in the IDE
Nota: the Contextual Menu appears, the MsgBox is displayed (but was not in the original project).
I forgot to note:
Plane Mode On
Wait a minute
Xojo Cache cleaned
Run Xojo only
Edit: typo add text.
Where is the code being run? In an event? If so, which?
ContextualMenuAction Event from a Listbox (in both cases)
What is really wrong is that I use it in the same condition('s).
I just checked the generated application on Windows 1803 and I get both Row and Cell as -1…
Are you trying to get the Click_Row and Click_Cell when you pressed right click or when you press left click on a menu? Because you’re doing the latter here if you’re calling this in ContextualMenuAction which could mean that depending on where the menu is pressed you could end up off the listbox and thus get an answer of -1
If you want to read the Click_Row and Click_Cell of the cell you clicked on when opening the menu you should run the code inside ConstructContextualMenu then store those values (e.g. in listbox properties) if you want to use them later inside ContextualMenuAction. Then if you are reading them inside ConstructContextualMenu you use x and y passed into the event and don’t need to do all the maths with things like System.MouseX etc.
I activate the ContextualMenu (either right-click / MousePar two digits click / ctrl-left click) on a populated Row and want to Be able to edit it (or something else like delete the Row).
I will do after lunch. (after reading your answer) I may have underlooked the code in my other project
As Julian said, if you are in ConstructContextualMenu (or MouseDown), you just use RowFromXY and ColumnFromXY, using x and y that are passed automatically to the event. No need for System.MouseX/Y.
@Julia: Thank you.
It seems that I do not checked (read) carefully enough the ConstructContextualMenu Event.
a. I add two window properties (My_X and My_Y As integer)
b. In ConstructContextualMenu, I store X and Y into My_X and My_Y,
c. I use these properties with RowFromXY and ColumnFromXY.
Just do it, Emile !
Result (after implementation): It Works !!!
Thank you all.
BTW: I forgot
Why this code I extracted from another project works there and not here ?
I do not knpw.
Glad you got it working!
Probably just luck that your menu selection is over the cell that you clicked to open the menu
Only the Shadow knows (from The Shadow comics)
Thank you all !
Or the code part I copied is not used and I forgot to remove (or comment) it. I have to check one day.