Application Development 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: 

How to set selected row on startup of an alv tree build with cl_salv_tree

Former Member
0 Kudos
986

HI,

I have a cl_salv_tree and want the tree structure to open a specific node when starting the report. My coding is something like that:

DATA: lr_selections TYPE REF TO cl_salv_selections_tree,

lr_nodes TYPE REF TO cl_salv_nodes,

lr_node TYPE REF TO cl_salv_node,

lv_node_index(12) TYPE c,

lt_nodes TYPE salv_t_nodes,

ls_nodes TYPE salv_s_nodes,

lr_item TYPE REF TO cl_salv_item.

lr_selections = lr_tree->get_selections( ).

lt_nodes = lr_selections->get_selected_nodes( ).

lr_item = lr_selections->get_selected_item( ).

IF lr_item IS NOT BOUND.

lr_nodes = lr_tree->get_nodes( ).

lr_node = lr_nodes->get_node( lv_node_index ). "lv_node_index is the index of the node i want to be open on startup

ls_nodes-key = lv_node_index.

ls_nodes-node = lr_node.

APPEND ls_nodes TO lt_nodes.

lr_selections->set_selected_nodes( lt_nodes ).

ELSE.

ls_nodes-node = lr_item->get_node( ).

ls_nodes-key = ls_nodes-node->get_key( ).

APPEND ls_nodes TO lt_nodes.

lr_selections->set_selected_nodes( lt_nodes ).

ENDIF.

This coding is also used, when the report is running and someone clicks an a row. So thats why I check if a item is marked

or the total row.

But the tree always starts without opening the node.

Do I use the right methods or am I totally wrong ????

Thx for your help in advance

dinodini

Edited by: dinodini on Nov 16, 2010 6:51 PM

3 REPLIES 3

naimesh_patel
Active Contributor
0 Kudos
343

What you are looking for is the similar functionality which could be achieved by the method EXPAND_NODE of the ALV Tree created using CL_GUI_ALV_TREE. In SALV Tree, you can use the method EXPAND of the class CL_SALV_NODE to show all the subnodes of that node, not by using the SELECTION.

Once you add the Node using the method ADD_NODE, you should call the method EXPAND to expand that subtree.


            lr_nodes  = lr_tree->get_nodes( ).
            lr_node =  lr_nodes->ADD_NODE( ... )
            lr_node->EXPAND( COMPLETE_SUBTREE = 'X' ).

Regards,

Naimesh Patel

0 Kudos
343

Thx Naimesh,

I will try this now. I don't know why I didn't searched for possible methods in the cl_salv_node and nodes classes.

Thx for your hint I think this will work.

dinodini

Former Member
0 Kudos
343

Thx this help was the one I was searching for