有些时候我们不想光标移动或者回车后才进入Data Change ,比如选择dropdown list 选择值后,希望跟随变更的其他字段实时的作出反应,则可通过以下方式实现。
1.声明 CALL_BACK
SET HANDLER GO_EVENT -> HANDLE_DELAYED_CALL_BACK FOR GO_ALV.
2.重定义HANDLE_DELAYED_CALL_BACK
HANDLE_DELAYED_CALL_BACK FOR EVENT DELAYED_CALLBACK OF CL_GUI_ALV_GRID.
IMPORTING SENDER.
3.实现HANDLE_DELAYED_CALL_BACK
METHOD HANDLE_DELAYED_CALL_BACK.
PERFORM ON_DELAYED_CALLBACK USING SENDER.
ENDMETHOD.
4.强制走data change.
FORM ON_DELAYED_CALLBACK USING SENDER TYPE REF TO CL_GUI_ALV_GRID.
CALL METHOD SENDER->CHECK_CHANGED_DATA.
ENDFORM.
5.调用方法(实例化ALV时)
CALL METHOD GO_ALV_DRID->REGISTER_DELAED_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MA_EVT_DELAYED_MOVE_CURR_CELL.
注意: 如果想连续点击同一个字段 可以在datachange后将光标移动到其他字段,如不需要则不用添加下列代码
CALL METHOD GO_ALV_GRID->SET_CURRENT_CELL_VIA_ID
EXPORTING
IS_ROW_ID = LS_ROW_ID
IS_COLUMN_ID = LS_COLUMN_ID
IS_ROW_NO = LS_ROW_NO.