cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the index of the clicked button on TOOLBARBUTTONCHOICE

Former Member
0 Kudos

Hello Experts,

I have used toolbarbuttonchoice and created the dropdown list of the buttons dynamically. now when any of the button is clicked i need to get the reference of the button to call appropriate code in the action, but i am unable to get the either the reference or index of the clicked button.

Please help.

Regards,

Kinshuk

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Have a look on the map_on_action method. You can dynamically add a parameter which will be transfered to the action handler:

CLEAR lt_parameters.

<b>INSERT INITIAL LINE INTO TABLE lt_parameters ASSIGNING <param1>.

<param1>-name = 'CE'.

<param1>-type = 'r'.

<param1>-object = lr_subelement.</b>

lr_choice = cl_wd_menu_action_item=>new_menu_action_item( ).

lr_choice->set_text( ls_auth-text ).

<b> lr_choice->map_on_action( lt_parameters ).</b>

In my case I transfer a context_element, but you can also use an integer which can be used in case in the action handler. In the action handler i just defined the import parameter CE type ref to if_wd_context_element.

lt_parameters is typer if_wd_event=>parameters.

Cheers,

Sascha

Message was edited by:

Sascha Dingeldey

Former Member
0 Kudos

Hi Sascha,

My code goes this way


  data:
    lr_btn_ch   type ref to if_wd_view_element,
    lr_toolbar_btn_choice type ref to cl_wd_toolbar_btn_choice,
    lr_row_data           type ref to cl_wd_row_data,
    item                  type string,
    action                type string.

CALL METHOD view->get_element
  EXPORTING
    id      = 'BTNCH'   " button choice Element in layout
  receiving
    element = lr_btn_ch
    .

lr_toolbar_btn_choice ?= lr_btn_ch.

DATA:  lt_items      type string_table,
    lt_actions    type string_table.

loop at lt_dyntab into ls_dyntab.
  append ls_dyntab-name to lt_items.
append 'ONBTNCH' to lt_actions.
endloop.  

i get the data in the table lt_dyntab from API not in context


  loop at Lt_items into item.
    read table Lt_actions index sy-tabix into action.
    create_choice_item( i_toolbar_btn_choice = lr_toolbar_btn_choice i_item = item i_action = action i_view = VIEW ).
  endloop.

create_choice_item creates the menu item for the button choice..

My question is where should i call the map_on_action method. and how do i retrieve the index or reference in ONBTNCH method.

please elaborate.

Regards,

Kinshuk

Former Member
0 Kudos

Hi Kinshuk.

You would call it in the create_choice_item method.

I assume each item calls the same action. Then just transfer an ID or the current loop index to your method.

In the method additionally call:

lr_choice_item->map_on_action( lt_parameters ).

Have a llok at component WDR_TESt_p00009 in V1 in method wddomodifyview.

To fill lt_parameters you would do something like this:

INSERT INITIAL LINE INTO TABLE lt_parameters ASSIGNING <param1>.

<param1>-name = 'ID'.

<param1>-type = 'g'.

<param1>-value = A ID OR AN INDEX

Then in you action BTNCH add the import parameter ID type string or i.

Now you can check out which item has been clicked.

Former Member
0 Kudos

Hi Sascha,

Thank you.. that works.

Regards,

Kinshuk

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

You can use parameter mapping in this case. Check it has some code inside.