Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Get selected function in a context menu with cl_gui_alv_grid

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello Alfredo

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

Regards,

Uwe

6 REPLIES 6

Former Member
0 Kudos

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

uwe_schieferstein
Active Contributor
0 Kudos

Hello Alfredo

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

Regards,

Uwe

0 Kudos

Thanks for the answers.

The problem i have with USER_COMMAND event of CL_GUI_ALV_GRID is that i can't determine the row of the ALV selected. I have te code function select, but i need the row selected, and this is not received has a parameter of the event,

Alfredo.

0 Kudos

The tool bar isn't the best mechanism to use for selecting Rows etc but should ideally be used for discrete functions like SAVE, UPDATE, DOWNLOAD TO EXCEL etc.

For data manipulation look at ON DATA CHANGED, ON DATA CHANGED FINISHED and DOUBLE CLICK.

Probably the easiest way is to use the double click event

methods on_dubbelklik

for event double_click of cl_gui_alv_grid

importing

!e_row

!e_column

!es_row_no .

methods dubbelklik

importing

!e_row type lvc_s_row

!e_column type lvc_s_col

!es_row_no type lvc_s_roid .

method constructor.

create object grid_container1

exporting

container_name = 'CCONTAINER1'.

create object grid1

exporting

i_parent = grid_container1.

set handler z_object->on_user_command for grid1.

set handler z_object->on_toolbar for grid1.

set handler z_object->handle_data_changed for grid1.

set handler z_object->handle_data_changed_finished for grid1.

set handler z_object->on_dubbelklik for grid1.

call method grid1->register_edit_event

exporting

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

endmethod.

method dubbelklik.

perform dubbelklik in program (caller) if found

using

e_row

e_column

es_row_no.

  • ...

endmethod.

Now in the application program

when a double click event is done the method calls routine dubbelklik in the calling program

The row / column nr and field name will be passed to your subroutine.

(In my calling class for the grid I make the calling program one of the parameters);

form dubbelklik using

e_row type lvc_s_row

e_column type lvc_s_col

es_row_no type lvc_s_roid.

read table <dyn_table> index e_row into wa_elements.

etc.

where <dyn_table> is my grid data table.

Any comparable method should work.

Cheers

jimbo

0 Kudos

Thanks James, the problem is that i have a multiple functions and with double click even i can only implement one function.

Finally, i have found a solution to get the selected cursor cell in the USER_COMMAND event of CL_GUI_GRID. Using que method GET_CURRENT_CELL of CL_GUI_ALV_GRID i can get the row index (parameter ES_ROW_ID). With this and user code function i can do my job =).

Thanks everybody for the answers.

Edited by: Alfredo Pradas on Jan 7, 2008 10:20 AM

0 Kudos

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