cancel
Showing results for 
Search instead for 
Did you mean: 

Checking if user has selected or deselected a tree node

ChrisPaine
Active Contributor
0 Kudos

Hello,

In the event handler of the On Action event of a tree node, I need to decide whether the user has selected the element or deselected it.

I thought to use the following:

data:  lo_node type ref to if_wd_context_node,
         lo_element type ref to if_wd_context_element,
         l_element_selected type abap_bool.

first I tried

* need to find out if this element was selected or deselected!
  l_element_selected = context_element->is_selected( ).

but it didn't work - so I tried

lo_node = context_element->get_node( ).
  lo_element = lo_node->get_lead_selection( ).

  if lo_element = context_element.
    l_element_selected = abap_true.
  else.
    l_element_selected = abap_false.
  endif.

This did work.

I'm slightly confused as to why the two did not give the same result?

I can see in the implementation why - gotta love being able to see how the engine works - but why is the node selection table not set? For future reference, is there some flow that has to happen before the selection gets set but after the lead selection is made? Or is this just an error in the handling of the tree node element?

Cheers,

Chris

Accepted Solutions (0)

Answers (2)

Answers (2)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>I'm slightly confused as to why the two did not give the same result?

This has always seemed somewhat counter intuative to me as well, but selection and LeadSelection are two different things. Selection is the secondary selection when you have multi selection on a table. LeadSelection is the primary selection (generally denoted by a slightly different shade of darkening in the selection button column). What isn't clear is that when testing for selection or getting all selected elements, the leadSelection element is NOT included in this. Therefore you often must test for leadSelection and selection. In these cases it might be better to set the selectionMode of your table to multiNoLead.

ChrisPaine
Active Contributor
0 Kudos

One would wonder why there is no is_Lead_Selected method. Having just the is _ Multi_ Selected method is quite confusing. Especially when the method description is "True, if element is selected in the node". One would assume that this would include lead selection.

Then again - when you consider the mismatch between methods that return values and methods that export values, this lack of a is_Lead_Selected method would be low down on my list of things to fix to make WDA more consistent.

Having Get_Static_Attributes return the data rather than export it would be much higher on my list - ( get_static_attributes_ref does actually return the reference to the data - talk about inconsistent! )

ChrisPaine
Active Contributor
0 Kudos

Clearly this question is not answered, but in order to ask other interesting and probably just as unlikely to be answered questions it is now going to be assigned the ridiculous status of "answered". If you feel that this is just nuts, please go to Idea Place and vote on idea 1151.

https://ideas.sap.com/ideas/1151