不会触发ALV树节点事件

时间:2016-02-24 12:01:51

标签: user-interface abap

当我在没有启用项目选择的情况下使用ALV树时遇到问题。在这种情况下,我无法接收节点上下文菜单请求的事件。 当我打开项目选择时,一切正常。 我得到节点和项目的上下文菜单请求的事件,但我不需要为我的应用程序启用项目选择。

以下是我可以分享的一些代码:

DATA: g_tree             TYPE REF TO cl_gui_alv_tree.
* create container for alv-tree
DATA: l_tree_container_name(30) TYPE c,
l_custom_container        TYPE REF TO cl_gui_custom_container.
l_tree_container_name = 'TREE'.

CREATE OBJECT l_custom_container
EXPORTING
  container_name              = l_tree_container_name
EXCEPTIONS
  cntl_error                  = 1
  cntl_system_error           = 2
  create_error                = 3
  lifetime_error              = 4
  lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
ENDIF.
* create tree control
CREATE OBJECT g_tree
EXPORTING
  parent                      = l_custom_container
  node_selection_mode         = cl_gui_column_tree=>node_sel_mode_single
  item_selection              = abap_true "WOULD LIKE TO HAVE THIS SET TO FALSE
  no_html_header              = abap_true
  no_toolbar                  = ''
EXCEPTIONS
  cntl_error                  = 1
  cntl_system_error           = 2
  create_error                = 3
  lifetime_error              = 4
  illegal_node_selection_mode = 5
  failed                      = 6
  illegal_column_name         = 7.
IF sy-subrc <> 0.
ENDIF.

我在这里注册活动:

FORM register_events.

DATA: lt_events TYPE cntl_simple_events,
    l_event   TYPE cntl_simple_event.

l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
APPEND l_event TO lt_events.

CALL METHOD g_tree->set_registered_events
  EXPORTING
    events                    = lt_events
  EXCEPTIONS
    cntl_error                = 1
    cntl_system_error         = 2
    illegal_event_combination = 3.
 IF sy-subrc <> 0.
 ENDIF.

DATA: l_event_receiver TYPE REF TO tree_event_receiver.
CREATE OBJECT l_event_receiver.

SET HANDLER l_event_receiver->handle_node_ctmenu_request
                                                    FOR g_tree.
SET HANDLER l_event_receiver->handle_node_ctmenu_selected
                                                    FOR g_tree.
SET HANDLER l_event_receiver->handle_item_ctmenu_request
                                                    FOR g_tree.
SET HANDLER l_event_receiver->handle_item_ctmenu_selected
                                                    FOR g_tree.

ENDFORM.

以下是我的处理程序:

METHOD handle_node_ctmenu_request.
  CALL METHOD menu->add_function
      EXPORTING
        fcode = 'DELETE_ITEM'
        text  = 'delete'.
ENDMETHOD.
METHOD handle_item_ctmenu_request.
CALL METHOD menu->add_function
      EXPORTING
        fcode = 'DELETE_ITEM'
        text  = 'delete'.
ENDMETHOD.

因此,当“item_selection”设置为true时,两种方法都有效。当“item_selection”设置为false时,它们都不起作用。但是,我希望在这种情况下会触发handle_node_ctmenu_request。

1 个答案:

答案 0 :(得分:0)

诀窍在于ALV树模型中不同类型事件的互连 官方SAP控制框架documentation声明:

  

如果设置参数item_selection =&#39; X&#39;当你创建了   例如,您还可以对以下事件做出反应:
  ...
  ITEM_CONTEXT_MENU_REQUEST
  ITEM_CONTEXT_MENU_SELECT
  ...

但是,不幸的是,它并没有表明(与SAP世界中的许多其他内容一样),Control Framework会处理池中的项目和节点事件。 因此,如果您使用已禁用的item_selection参数注册与项目相关的事件,则与节点相关的事件也将无效
换句话说,不要注册与项目相关的事件,如果您想要对与节点相关的事件做出反应,或者将此参数设置为&#34;已启用&#34;。