- OOALV的单击事件通过cl_gui_alv_grid内置事件hotspot_click实现,效果如下图显示
- 实现步骤:
- 在Fieldcat中设置参数HOTSPOT参数,将列设置成热点。单击事件要和热点组合才能触发
gs_fieldcat-hotspot = 'X'. "热点
- 定义一个事件处理类及其操作处理
CLASS cl_event DEFINITION. PUBLIC SECTION. METHODS handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id "行信息的值 e_column_id. "列信息的值 ENDCLASS. CLASS cl_event IMPLEMENTATION. METHOD handle_hotspot_click. DATA lv_index TYPE i. FIELD-SYMBOLS <fs_fieldname> TYPE any. "ALV内表的索引 lv_index = e_row_id-index. " READ TABLE gt_data INTO gw_data INDEX lv_index. IF sy-subrc = 0 . "e_column_id-fieldname 列信息的字段名 "根据列信息的字段名去找结构对应字段的值 ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE gw_data TO <fs_fieldname>. DATA(lv_message) = |您点击第{ lv_index }行的{ <FS_FIELDNAME> }|. MESSAGE lv_message TYPE 'I'. ENDIF. ENDMETHOD. ENDCLASS.
- 通过事件处理类的实例对象给OOALVDUI的实例对象设置注册事件
CREATE OBJECT go_con EXPORTING container_name = 'CONTORL'. CREATE OBJECT go_alv EXPORTING I_parent = go_con. DATA(lo_event) = NEW cl_event( ). SET HANDLER lo_event->handle_hotspot_click FOR go_alv.