data_change 使用 cl_gui_alv_grid - 对 Enter 键没有反应

data_change using cl_gui_alv_grid - not reacting to Enter key

我想在另一个字段被编辑时填充一个字段。所以这是实现中的方法。

当我按 Enter 时没有任何反应,但当我双击时更改应用。

你有什么想法或解决办法吗?我正在使用 class cl_gui_alv_grid.

METHOD data_changed_finished.
DATA: ls_inr   TYPE LINE OF lvc_t_modi,
      lv_stbl  TYPE lvc_s_stbl,
      gt_out type standard table of SPFLI,
      ls_out   LIKE LINE OF gt_out.


LOOP AT et_good_cells INTO ls_inr
  WHERE fieldname = 'CITYFROM'. 
  EXIT.
ENDLOOP.

DATA:
  ld_REFRESH_MODE TYPE SALV_DE_CONSTANT ,
  ld_S_STABLE TYPE LVC_S_STBL.
  ld_S_STABLE-row = 'X'.
  ld_S_STABLE-col = 'X'.

IF sy-subrc = 0.
  LOOP AT et_good_cells INTO ls_inr.
    LOOP AT IT_SPFLI INTO ls_out
                   FROM ls_inr-row_id
                   TO ls_inr-row_id.
      
      ls_out-DISTANCE = '556'.
      MODIFY IT_SPFLI FROM ls_out.

    ENDLOOP.
  ENDLOOP.

ENDIF.


  lv_stbl-row = 'X'.
  lv_stbl-col = 'X'. 

  ld_S_STABLE-row = 'X'.
  ld_S_STABLE-col = 'X'.
  ld_REFRESH_MODE = 2. 
  
  CALL METHOD salv->REFRESH(
  EXPORTING
  REFRESH_MODE = ld_REFRESH_MODE
  S_STABLE = ld_S_STABLE ).

ENDMETHOD.

所以,正如我在评论中所说,对我来说很明显,问题更多的是关于 CL_GUI_ALV_GRID(而不是 CL_SALV_TABLE)。默认情况下,Enter 键不会触发事件 DATA_CHANGEDDATA_CHANGED_FINISHED.

如果您想要此功能,您必须调用方法 REGISTER_EDIT_EVENT 并传递这两个常量之一以同步触发两个事件:

  • MC_EVT_ENTER:事件将总是在按下 Enter 时触发,即使没有更改任何单元格
  • MC_EVT_MODIFIED : 一旦 一个单元格被更改并且按下 Enter 或焦点更改到另一个单元格,事件将被触发