Skip to Content
author's profile photo Former Member
Former Member

Get selected function in a context menu with cl_gui_alv_grid

Hi,

I'm trying to implement a context menu on a alv grid. I defined and implemented a method for the event CONTEXT_MENU_REQUEST to add function codes to context menu. It works ok.

The problem is retrieving the function selected in context menu. I tried to define in the class definition a method for event CONTEXT_MENU_SELECTED (that seems to be the event to use) but i can't implement it because is defined as protected event in CL_GUI_ALV_GRID.

How i can implement a method to catch this event and determine te function code defined in the context menu??

Thanks.

Edited by: Alfredo Pradas on Jan 4, 2008 5:35 PM

Edited by: Alfredo Pradas on Jan 4, 2008 5:36 PM

Edited by: Alfredo Pradas on Jan 4, 2008 5:37 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jan 04, 2008 at 06:56 PM

    Hello Alfredo

    The context menu function is handled by the event USER_COMMAND of CL_GUI_ALV_GRID.

    Regards,

    Uwe

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi there

      Thanks for the tip

      I've used this as well

      In my toolbar i now have

      
      move 0 to ls_toolbar-butn_type.
          move 'TEST' to ls_toolbar-function.
          move space to ls_toolbar-disabled.
          move icon_execute_object to ls_toolbar-icon.
           move 'Get Cell' to ls_toolbar-quickinfo.
           move  'CELL' to ls_toolbar-text.
      
          append ls_toolbar to e_object->mt_toolbar.
          clear ls_toolbar.
      
      

      In the on_user_command

      
       when 'TEST'.
              call method me->get_cell.
      

      In my get_cell method

      
      method get_cell.
      break-point 1.
      call method grid1->get_current_cell
      importing
      e_row     = ls_row
      e_value   = ls_value
      e_col     = ls_col
      es_row_id = ls_row_id
      es_col_id = ls_col_id
      es_row_no = ls_row_no.
      * pass back parameters to a routine in the calling program
      perform handle_cell in program (caller)  if found
       using
       * ====> parmeters from the method 
      endmethod.
      

      I can then do whatever I want with the data .

      What I usually do here is to add the following code to my calling application

      
      Form handle_cell 
          using   parameters from method
      
      do whatever the application needs
      
      endform.
      
      

      This will also work if I select multiple rows / columns / both (using a similar method).

      In my ALV handling class I usually make the calling program a parmeter as it's often IMO easier to retrieve the data via the method and then process it in the application program -- makes the class more generic as well.

      In my application program the current Grid table is alwys available as a dynamic table <dyn_table> so I can use / manipulate the data directly if required.

      Thanks for your tip of using the ON User Command for handling cell selection.

      Cheers

      jimbo

  • author's profile photo Former Member
    Former Member
    Posted on Jan 04, 2008 at 06:29 PM

    for context menu, u cna this cl_alv_event_toolbar_set.

    CLASS alv DEFINITION.

    PUBLIC SECTION.

    *context menu

    METHODS handle_toolbar

    FOR EVENT toolbar OF cl_gui_alv_grid

    IMPORTING e_object e_interactive.

    ENDCLASS.

    CLASS lcl_alv IMPLEMENTATION.

    *context Toolbar buttons

    METHOD handle_toolbar.

    PERFORM modify_toolbar USING e_object.

    ENDMETHOD.

    endclass.

    FORM modify_toolbar USING p_e_object TYPE REF TO

    cl_alv_event_toolbar_set.

    pass the corr. values to the foll.

    FUNCTION

    ICON

    QUICKINFO

    BUTN_TYPE

    DISABLED

    TEXT

    CHECKED

    and appenmd these values ot the p_e_object.

    and handle reamining req. fun. in user command routine.

    endform

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.