CL_GUI_ALV_GRID 触发PAI事件(Application event)

*&---------------------------------------------------------------------*
*& Report  Z_BARRY_ALV_GRID_EVENT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_barry_alv_grid_event.

DATA: itab TYPE TABLE OF sflight .
DATA: ok_code LIKE sy-ucomm .
DATA: go_grid             TYPE REF TO cl_gui_alv_grid,
      go_custom_container TYPE REF TO cl_gui_custom_container.

CLASS lcl_event_receiver DEFINITION DEFERRED .
DATA: event_receiver TYPE REF TO lcl_event_receiver.

*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS catch_doubleclick
    FOR EVENT double_click OF cl_gui_alv_grid
    IMPORTING e_row
              e_column
              es_row_no .
ENDCLASS.                    "lcl_event_receiver DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD catch_doubleclick.
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'BACK'.
    CALL METHOD cl_gui_cfw=>flush.
  ENDMETHOD.                    "catch_doubleclick
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION

START-OF-SELECTION.
  CALL SCREEN 0100 .

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'MAIN100'.
  IF go_grid IS INITIAL.
    CREATE OBJECT go_grid
      EXPORTING
        i_parent = cl_gui_container=>screen0.

    CREATE OBJECT event_receiver.
    SET HANDLER event_receiver->catch_doubleclick FOR go_grid.

    SELECT * FROM sflight INTO TABLE itab UP TO 10 ROWS.

    CALL METHOD go_grid->set_table_for_first_display
      EXPORTING
        i_structure_name = 'SFLIGHT'
      CHANGING
        it_outtab        = itab.
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE ok_code.
    WHEN 'BACK'.
      LEAVE PROGRAM.
  ENDCASE.
  CLEAR ok_code .
ENDMODULE.                 " USER_COMMAND_0100  INPUT

另注:CL_GUI_ALV_GRID的SET_REGISTERED_EVENTS方法系统没有实现,不让使用

文章转载自:http://blog.chinaunix.net/uid-8527621-id-2029831.html

posted @ 2015-08-13 10:22  Shelwin的世界  阅读(1944)  评论(0编辑  收藏  举报