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: 

Setting the selection on the double-click event of ALV grid

abhay_sah
Advisor
Advisor
0 Kudos

Hi,

I have a requirement that I am working on and looking for some pointers for one of the issues that I am facing now.

Requirement :

To build a parent-child relationship between two sap gui screens.

The parent screen is displaying an ALV grid (using cl_gui_alv_grid class) .

On Double-clicking on a particular record in the ALV , the corresponding details are displayed  in the child screen.

The double click is handled(method)by a non-local class.

This is modeled and is working well.

Issue :

When I double click on any specific ALV record, the details are displayed correctly(below) in the

child screen but the ALV record is not highligted/selected in the ALV grid (so this is confusing/no information for the user).

I tried the following :

get_selected_nodes and set_selected_nodes methods.

cl_gui_cfw=>flush

refresh_table_display .

The double-clicked record is not highlighted.  

Is there anything missing ? I have gone through some of the other blogs as well , a double-click is what is required .


Regards,

Abhay


[Note : The screens are configured using BDT framework , but the that should not be a problem as the PBO is getting

called again ]

1 ACCEPTED SOLUTION

Patrick_vN
Active Contributor
0 Kudos

Use the SET_SELECTED_ROWS method to highlight the lines you require.

Also check the parameters of the REFRESH_TABLE_DISPLAY in case of scrolling problems.

17 REPLIES 17

Patrick_vN
Active Contributor
0 Kudos

Use the SET_SELECTED_ROWS method to highlight the lines you require.

Also check the parameters of the REFRESH_TABLE_DISPLAY in case of scrolling problems.

0 Kudos

I have tried both get_selected_rows and set_selected_rows.

[Also, tried setting in the debugging. ]

0 Kudos

I've done exactly the same in the past using the SET_SELECTED_ROWS method.


No offense intended, but are you only refreshing the alv in the PBO of the screen? Or are you instantiating the objects all over again?

0 Kudos

Sure.

I am creating  single instance of the container and the grid and made it global.

So it’s the same instance that I use.

I tried a few combinations of the below call sequence. Open for sugestions.:

CALL METHOD go_alv_meap->set_table_for_first_display

CALL METHOD go_alv_meap->get_selected_rows

    IMPORTING

      et_index_rows = lt_index_rows.

CALL METHOD go_alv_meap->set_selected_rows

    EXPORTING

      it_index_rows = lt_index_rows.

go_alv_meap->refresh_table_display( ).

CALL METHOD cl_gui_cfw=>flush.

(May be BDT has also a role to play)

0 Kudos

Nope, I meant the process before output. Do you check if the GO_ALV_MEAP object exists (and only refresh it if it does)? Or are you re-instantiating it each round-trip?

0 Kudos

Not sure if I get you . But if the go_alv_meap instance doesnt exist, then the method call will dump with null reference.

0 Kudos

Is your PBO structured like this?

IF gr_alvgrid IS INITIAL .

    CREATE OBJECT gr_ccontainer

 

    CREATE OBJECT gr_alvgrid

 

    PERFORM prepare_field_catalog CHANGING gt_fieldcat.

    PERFORM prepare_layout CHANGING gs_layout .

    CALL METHOD gr_alvgrid->set_table_for_first_display

ELSE .

    CALL METHOD gr_alvgrid->refresh_table_display

ENDIF .

0 Kudos

No , at the moment , the if contains only the object creation part (there is no else) .

Then its the below sequence :

CALL METHOD go_alv_meap->set_table_for_first_display

CALL METHOD go_alv_meap->get_selected_rows

    IMPORTING

      et_index_rows = lt_index_rows.

CALL METHOD go_alv_meap->set_selected_rows

    EXPORTING

      it_index_rows = lt_index_rows.

     CALL METHOD go_alv_meap->check_changed_data

       IMPORTING

         e_valid   = lv_valid

**       CHANGING

**         c_refresh = 'X'

*         .

   IF lv_valid = 'X'.

     go_alv_meap->refresh_table_display( ).

   ENDIF.

   CALL METHOD cl_gui_cfw=>flush.



I've tried always calling them , setting values in debugging as well . Also it seems cl_gui_alv_grid has a private attribute mt_selected_rows.

0 Kudos

There are no selected rows if you recreate (or reinstantiate) the ALV object. That resets everything.

Try adding the if statement, and create the GO_ALV_MEAP only once. That will do the trick.

0 Kudos

Thanks Patrick. As I mentioned, the go_alv_meap is created only once there is no other instance created.

0 Kudos

Nope, if you don't include the IF statement, the GO_ALV_MEAP is created each time you have a round-trip (when the user presses a button, triggers an event, etc).

If you don't believe me, just put a break-points on the create object and the set_table_for_first_display method. If you stop there more then once -> troubles

0 Kudos

I believe you

No it doesnt get called multiple times am taking care of that. Though the framework does flip some global_guid value for the instance between the refresh calls , but that could be internally for the framework .

I have fixed the issue.

The problem was in the sequence of the get_selected_rows and set_selected_rows.

I was calling the get_selected_rows and set_selected_rows after calling set_table_for_first_display .

The selected rows value in m_selected_rows attribute of cl_gui_alv_grid was getting cleared.

I am now calling the get_selected_rows before calling  set_table_for_first_display and then calling the set.

I should have observed this earlier.

Thanks for spending some time on this. Appreciate.

0 Kudos

You're welcome

Chintu6august
Contributor
0 Kudos

Hi,

to highlight the lines in grid alv

create an event handler method

ex: handle_del FOR EVENT delayed_changed_sel_callback OF cl_gui_alv_grid.


call method in the method handle_del

      CALL METHOD grid1->get_selected_rows

        IMPORTING

          et_index_rows = isel

then  after set table for first display call SET_SELECTED_ROWS method.


thanks!!

0 Kudos

Thanks Chintu. Can this not be handled in the double-click event ? Do I have to  handle the other event as well ?

0 Kudos

you need not to handle it in your double click method..

just define a event handler method like you did for double_click event and implement it..

after implementing register it with the grid instance.

all steps will be same as you followed to handle double click.

you can refer this link

0 Kudos

Thanks Chintu.