cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with itemlistbox display

Former Member
0 Kudos

I have an itemlistbox which I populate from a table. It's set to multiselect. I can pick and save the selections to a table with no problems. What I can't seem to figure out is how to get the itemlistbox to set the index(s) based on the data. When the itemlistbox loads nothing is selected. How can I pass a table of records to the itemlistbox so that they appear selected?

Accepted Solutions (1)

Accepted Solutions (1)

former_member215632
Discoverer
0 Kudos

Hi,

Web Dynpro selection logic is stored in context objects - node and elements. You can use method set_selected of node or element to select specific items.

For example:

DATA: lr_node TYPE REF TO if_wd_context_node,

         lt_rows TYPE wdr_context_element_set,

         lr_elem TYPE REF TO if_wd_context_element.

   lr_node = wd_context->get_child_node( name = 'TEST_NODE' ).

* Set first element selected 

   lr_node->set_selected( flag = 'X' index = 1 ).

* Set all elements selected looping at index

   DO lr_node->get_element_count( ) TIMES.

     lr_node->set_selected( flag = 'X' index = sy-index ).

   ENDDO.

* Set all elements selected looping at element reference

   lt_rows = lr_node->get_elements( ).

   LOOP AT lt_rows INTO lr_elem.

     lr_elem->set_selected( flag = 'X' ).

   ENDLOOP.

Former Member
0 Kudos

Thanks a million. I just couldn't seem to figure it out yesterday but that's exactly what I needed!

Answers (1)

Answers (1)

former_member217916
Participant
0 Kudos

Hi,

In addition to what Sergey said you can also get the value of each attribute and set the flag depending on some business logic.

For example

LOOP AT lt_rows INTO lt_elem.

       lt_elem->get_attribute(

                 EXPORTING name = 'ID'          "Attribute name          

                 IMPORTING value = l_value ).  "Attribute variable


* You can put some business rules here to check for which rows you would like pre-select

       IF l_value CS 'A'.

          lt_elem->set_selected( flag = 'X').

       ENDIF.     

ENDLOOP.

Regards,

Karan