Listbox ContextualMenu (Row, Column)

  1. 3 months ago

    Emile S

    May 16 Europe (France, Strasbourg)
    Edited 3 months ago

    The code below comes from a working project and do not works in another project (returns )1 for both Row, Cell):

     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"
        Return True
      End If

    No container control…

    Conditions:
    run in the IDE
    El Capitan
    Xojo 2015r1

    Nota: the Contextual Menu appears, the MsgBox is displayed (but was not in the original project).

    I forgot to note:
    Plane Mode On
    Power Off,
    Wait a minute
    Power ON
    Xojo Cache cleaned
    Run Xojo only

    Edit: typo add text.

  2. Julian S

    May 16 Pre-Release Testers, Xojo Pro UK

    Where is the code being run? In an event? If so, which?

  3. Emile S

    May 16 Europe (France, Strasbourg)

    Thanks Julian.

    ContextualMenuAction Event from a Listbox (in both cases)

    What is really wrong is that I use it in the same condition('s).

  4. Emile S

    May 16 Europe (France, Strasbourg)
    Edited 3 months ago

    I just checked the generated application on Windows 1803 and I get both Row and Cell as -1...

  5. Julian S

    May 16 Pre-Release Testers, Xojo Pro UK

    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

  6. Julian S

    May 16 Pre-Release Testers, Xojo Pro UK

    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.

  7. Emile S

    May 16 Europe (France, Strasbourg)

    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

  8. Julia T

    May 16 Sandy Hook, Connecticut

    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.

  9. Emile S

    May 16 Europe (France, Strasbourg)

    @Julia: Thank you.

    It seems that I do not checked (read) carefully enough the ConstructContextualMenu Event. :)

    Conclusion:
    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 !

  10. Emile S

    May 16 Europe (France, Strasbourg)

    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.

  11. Julian S

    May 16 Pre-Release Testers, Xojo Pro UK
    Edited 3 months ago

    Glad you got it working!

    @Emile S Why this code I extracted from another project works there and not here

    Probably just luck that your menu selection is over the cell that you clicked to open the menu :)

  12. Emile S

    May 16 Europe (France, Strasbourg)

    Only the Shadow knows (from The Shadow comics)…

    Thank you all !

  13. Emile S

    May 18 Europe (France, Strasbourg)

    @Julian S Probably

    Or the code part I copied is not used and I forgot to remove (or comment) it. I have to check one day.

or Sign Up to reply!