CL_GUI_ALV_TREE链接单击节点

时间:2015-07-09 07:34:09

标签: abap dynpro

我想在链接点击节点上捕获事件。我知道如何设置链接点击列项,就像:

DATA: ls_layout TYPE lvc_s_layi,
      lt_layout TYPE lvc_t_layi.

ls_layout-fieldname = 'Fieldname from table passing to alv tree'.
ls_layout-class = cl_gui_column_tree=>item_class_link.
APPEND ls_layout to lt_layout.

 o_cl_gui_tree->add_node(
    EXPORTING
      "other parameters...
      it_item_layout       = lt_layout
      "other parameters...
  ).

但我不知道如何在节点上设置链接点击。你可以帮帮我吗?感谢。

1 个答案:

答案 0 :(得分:0)

我无法理解,与所有其他事件处理实践相比,此事件处理案例中应该有什么困难/不同。但也许这是我自己的错。所以,让我们一步一步地做到这一点。观看并学习。 : - )

事件接收器的定义如下:

CLASS lcl_tree_event_receiver DEFINITION.
PUBLIC SECTION.
.
.
.
 METHODS handle_link_click
  FOR EVENT link_click OF cl_gui_alv_tree
  IMPORTING node_key
            fieldname.

ENDCLASS.

让我们实施课程。

CLASS lcl_tree_event_receiver IMPLEMENTATION.
.
.
.
 METHOD handle_link_click.
    " Do whatever You want in here. 
ENDMETHOD.                    "handle_link_click
ENDCLASS.

树事件的激活应该传递正确的ID

  DATA: lt_events TYPE cntl_simple_events,
  l_event   TYPE cntl_simple_event.
  .
  .
  l_event-eventid = cl_gui_column_tree=>EVENTID_LINK_CLICK.
  " yes, that works, in fact this constant is inside 
  " CL_ITEM_TREE_CONTROL

  APPEND l_event TO lt_events.
   CALL METHOD go_main_tree->set_registered_events
EXPORTING
  events                    = lt_events
EXCEPTIONS
  cntl_error                = 1
  cntl_system_error         = 2
  illegal_event_combination = 3.

最后我们实例化处理程序类并注册处理程序,它们看起来像:

  DATA: l_tree_event_receiver TYPE REF TO lcl_tree_event_receiver.
  CREATE OBJECT   l_tree_event_receiver.


   SET HANDLER l_tree_event_receiver->handle_link_click.
   FOR go_main_tree.

如果您想检查设置事件的作用,请致电

   CALL METHOD go_main_tree->get_registered_events
   IMPORTING
     events = lt_events.