Share |

Add button to ALVtree toolbar


Insert the following code into the PBO of the screen after the ALVtree has been created.
   i.e after 'CALL METHOD gd_tree->set_table_for_first_display' has been executed.


*&-------------------------------------------------------------*
*&      CHANGE_TOOLBAR
*&-------------------------------------------------------------*

* get toolbar control
  call method gd_tree->get_toolbar_object
          importing
              er_toolbar = mr_toolbar.

  check not mr_toolbar is initial.

* add seperator to toolbar
  call method mr_toolbar->add_button
          exporting
              fcode     = ''
              icon      = ''
              butn_type = cntb_btype_sep
              text      = ''
              quickinfo = 'This is a Seperator'.         "#EC NOTEXT

* add Standard Button to toolbar (for Delete Subtree)
  call method mr_toolbar->add_button
          exporting
              fcode     = 'DELETE'           "Function code of button
              icon      = '@18@'             "Icon ID (see )
              butn_type = cntb_btype_button  "Button type
              text      = ''                 "Button text
              quickinfo = 'Delete subtree'.  "Quick info text

* add Dropdown Button to toolbar (for Insert Line)
  call method mr_toolbar->add_button
          exporting
              fcode     = 'INSERT_LC'         "Function code of button
              icon      = '@17@'              "Icon ID (see )
              butn_type = cntb_btype_dropdown "Button type
              text      = ''                  "Button text
              quickinfo = 'Insert Line'.      "Quick info text

* set event-handler for toolbar-control
  data: toolbar_event_receiver type ref to lcl_toolbar_event_receiver.

  create object toolbar_event_receiver.
  set handler toolbar_event_receiver->on_function_selected
                                                      for mr_toolbar.
  set handler toolbar_event_receiver->on_toolbar_dropdown
                                                      for mr_toolbar.