Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

auto select tree checkbox

Former Member
0 Likes
492

Hi,

I am using class cl_gui_alv_tree, how can I set the checkbox of the nodes? I know there are similar messages posted but it doesn;t answer the question. So can someone please help.

Thx.

2 REPLIES 2
Read only

Former Member
0 Likes
428

CLASS zlcl_tree_event_receiver DEFINITION.

PUBLIC SECTION.

*§2. Define an event handler method for each event you want to react to.

METHODS handle_node_checkbox_change

FOR EVENT checkbox_change OF cl_gui_alv_tree

IMPORTING node_key sender.

  • 'sender' is an implicit event parameter that is provided by

  • ABAP Objects runtime system. It contains a reference to the

  • object that fired the event. You may directly use it to

  • call methods of this instance.

ENDCLASS. "zlcl_tree_event_receiver DEFINITION

******************************************************************

CLASS zlcl_tree_event_receiver IMPLEMENTATION.

*§3. Implement your event handler methods.

METHOD handle_node_checkbox_change.

data: lt_children type lvc_t_nkey.

data: ls_child type lvc_s_nkey.

data: ls_outtab_line type zso_struc_prodsel.

data: ls_lvc_s_laci type lvc_s_laci.

data: lt_lvc_t_laci type lvc_t_laci.

data: ls_node_layout TYPE lvc_s_lacn.

*first check if the node is a leaf, i.e. can not be expanded

refresh: gt_sel_items.

CALL METHOD tree1->GET_CHECKED_ITEMS

IMPORTING

ET_CHECKED_ITEMS = gt_sel_items.

  • If parent node's checkbox is selected, auto-select corresponding children

  • Get children

loop at gt_Sel_items into gs_Sel_items.

refresh lt_children.

CALL METHOD tree1->GET_CHILDREN

EXPORTING

I_NODE_KEY = gs_Sel_items-nodekey

IMPORTING

ET_CHILDREN = lt_children

EXCEPTIONS

HISTORIC_ERROR = 1

NODE_KEY_NOT_FOUND = 2

others = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • build parent - child relationship in GT_HIER for use in routine GENERATE_SORD_ITEM

gs_hier-node = gs_hier-parent = gs_sel_items-nodekey.

  • Set children's checkbox

loop at lt_children into ls_child.

CALL METHOD tree1->get_outtab_line

EXPORTING

i_node_key = ls_child-node_key

IMPORTING

e_outtab_line = ls_outtab_line.

IF not ( ls_outtab_line-svc_type IS INITIAL ).

CLEAR: ls_lvc_s_laci, ls_node_layout.

ls_lvc_s_laci-fieldname =

tree1->c_hierarchy_column_name.

ls_lvc_s_laci-u_chosen = 'X'.

ls_lvc_s_laci-chosen = 'X'.

APPEND ls_lvc_s_laci TO lt_lvc_t_laci.

CALL METHOD tree1->change_node

EXPORTING

i_node_key = ls_child-node_key

i_outtab_line = ls_outtab_line

is_node_layout = ls_node_layout

it_item_layout = lt_lvc_t_laci.

ENDIF.

gs_hier-node = ls_child-node_key.

append gs_hier to gt_hier.

endloop.

if sy-subrc ne 0.

clear gs_hier-parent.

append gs_hier to gt_hier.

endif.

endloop.

call method tree1->frontend_update.

ENDMETHOD. "handle_node_checkbox_change

Read only

Former Member