如何在 ALV 网格中 select 整行?

How to select full row in ALV grid?

我需要 return 到代码中带有 cl_gui_alv_grid 的 ALV 中的特定行。我使用 set_current_cell_via_id,它有效,但只有一个单元格被 selected。如何以编程方式 select 整行?

谢谢

完整代码:

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gt_t005t TYPE TABLE OF t005t.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF gr_alvgrid IS NOT BOUND.
    CREATE OBJECT gr_alvgrid
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    SELECT * FROM t005t INTO TABLE gt_t005t WHERE spras = 'E'.
    gr_alvgrid->set_table_for_first_display(
        EXPORTING i_structure_name = 'T005T'
        is_layout = VALUE #( sel_mode = 'D' )
        CHANGING it_outtab = gt_t005t ).
  ENDIF.
  DATA sroid TYPE lvc_s_roid.
  DATA irow TYPE i VALUE 2.
  SROID-ROW_ID = iRow.
  CALL METHOD gr_alvgrid->set_current_cell_via_id
    EXPORTING
      IS_ROW_NO = SROID.

使用方法SET_SELECTED_ROWS得到这个结果:

完整代码:

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gt_t005t TYPE TABLE OF t005t.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF gr_alvgrid IS NOT BOUND.
    CREATE OBJECT gr_alvgrid
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    SELECT * FROM t005t INTO TABLE gt_t005t WHERE spras = 'E'.
    gr_alvgrid->set_table_for_first_display(
        EXPORTING i_structure_name = 'T005T'
        is_layout = VALUE #( sel_mode = 'D' )
        CHANGING it_outtab = gt_t005t ).
  ENDIF.
  gr_alvgrid->set_selected_rows( it_row_no = VALUE lvc_t_roid( ( row_id = 2 ) ) ).