'Request context menu on click button in cl_gui_alv_tree

In my task, it is necessary to call the context menu by clicking the button located in the cell alv tree. To do this, I overridden the dispatch method and call tree object direct.

    me->mr_column_tree->dispatch( eventid = cl_gui_column_tree=>eventid_item_context_menu_req
                  cargo   = space
                  is_shellevent = space ).

I got the result I wanted, but the menu appears either at the zero position or at the point of the previous left mouse click.

An attempt to implement the display of the context menu also did not lead to the desired result. Application crashes with an error CNTL_ERROR

What are the ways to draw the context menu?

    cl_ctxmnu_mgr=>create_proxy( EXPORTING menu = io_ctmenu
                                 CHANGING guiobject = lo_gui
                                 EXCEPTIONS OTHERS = 1 ).
    CHECK sy-subrc = 0.
    CAST cl_gui_object( me )->call_method( EXPORTING method = 'SetContextMenu'
                                         p_count = 1
                                         p1 = lo_gui->H_CONTROL
                            EXCEPTIONS OTHERS = 1 ).


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source