Application Development and Automation 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: 
Read only

Copy OO ALV print button functionality

Karan_Chopra_
Active Participant
0 Likes
5,043

Hi Experts,

I need to trigger cl_gui_alv_grid print button event (in toolbar) in my custom button in toolbar.

How can this be done. Basically I need to capture the what print button does and into my custom button create din ALV toolbar itself.

1 ACCEPTED SOLUTION
Read only

former_member302911
Active Participant
0 Likes
3,684

Pass the Function Code &PRINT to custom button when handle the CL_GUI_ALV_GRID->TOOLBAR Event.

Example:


MOVE '&PRINT'              TO lst_toolbar-function.

MOVE ICON_PRINT      TO lst_toolbar-icon.

MOVE 'Print'                     TO lst_toolbar-quickinfo.

MOVE 'Print'                     TO lst_toolbar-text.


INSERT lst_toolbar        INTO e_object->mt_toolbar INDEX 1.

CLEAR lst_toolbar.

Regards,

Angelo.

20 REPLIES 20
Read only

Former Member
0 Likes
3,684

Hello,

You need to use custom handle toolbar using local class declaration.

Demo Program: BCALV_TEST_GRID_EVENTS

Snippet code for your ref.

Local class definition.

CLASS lcl_event_class DEFINITION FINAL.

   PUBLIC SECTION.

     METHODS:

     handle_data_changed

         FOR EVENT data_changed OF cl_gui_alv_grid

             IMPORTING er_data_changed,

     handle_toolbar

         FOR EVENT toolbar OF cl_gui_alv_grid

             IMPORTING e_object e_interactive,

     handle_menu_button

         FOR EVENT menu_button OF cl_gui_alv_grid

             IMPORTING e_object e_ucomm,

     handle_user_command

         FOR EVENT user_command OF cl_gui_alv_grid

             IMPORTING e_ucomm.

ENDCLASS. "lcl_event_receiver DEFINITION


To add custom button on Toolbar

*----------------------------------------------------------------------*

* Method handle_toolbar IMPLEMENTATION

*----------------------------------------------------------------------*

CLEAR gs_toolbar.

     MOVE c_exe TO gs_toolbar-function.

* --> This function code is evaluated in 'handle_menu_button'

     MOVE icon_execute_object TO gs_toolbar-icon.

     MOVE text-013 TO gs_toolbar-quickinfo.

     MOVE 0 TO gs_toolbar-butn_type.

     MOVE space TO gs_toolbar-disabled.

     INSERT gs_toolbar  INTO e_object->mt_toolbar INDEX 1.


Handling Custom Tool Bar button click.


*----------------------------------------------------------------------*

* Method handle_user_command IMPLEMENTATION

*----------------------------------------------------------------------*

   METHOD handle_user_command.

* § 4.At event USER_COMMAND query the function code of each function

*     defined in step 3.

*.........

* Part III : Evaluate user command to invoke the corresponding

*                   function.

*.........


* go to other table

     CASE e_ucomm.

       WHEN c_exe.

         CALL METHOD gc_grid->check_changed_data.


           PERFORM update_condition USING it_output1.

     ENDCASE.

   ENDMETHOD.                           "handle_user_command




*----------------------------------------------------------------------*

* Method handle_menu_button IMPLEMENTATION

*----------------------------------------------------------------------*

   METHOD handle_menu_button.

* § 3.At event MENU_BUTTON query your function code and define a

*     menu in the same way as a context menu.

*..........

* Part II: Evaluate 'e_ucomm' to see which menu button of the toolbar

*          has been clicked on.

*          Define then the corresponding menu.

*          The menu contains function codes that are evaluated

*          in 'handle_user_command'.

*...........

*  query e_ucomm to find out which menu button has been clicked on

     IF e_ucomm = c_exe.

       CALL METHOD e_object->add_function

         EXPORTING

           fcode = c_exe

           text  = text-013. "Overview

     ENDIF.

   ENDMETHOD.                    "handle_menu_button




Regards,

Sameer


Read only

0 Likes
3,684

And of course you need to register the handlers:

refer to form d0100_set_grid_events in the program which Sameer already pointed out: BCALV_TEST_GRID_EVENTS

Read only

rosenberg_eitan
Active Contributor
0 Likes
3,684

Hi,

Search for a book "An Easy Reference for ALV Grid Control.pdf"

http://scn.sap.com/docs/DOC-10353

Then page check chapter "Overriding Standard Functions "

Regards.

Read only

rahul_mb
Active Participant
0 Likes
3,684

Hi,

I hope you have already placed a custom button on teh ALV toolbar and have handled the user command in your program. If this is done, then when the function code for the new custom is triggered, call the method RAISE_EVENT of the class CL_GUI_ALV_GRID and pass the function code of the standard PRINT button in the ALV to it.

Regards,

Rahul MB

Read only

0 Likes
3,684

Hello Rahul,,

Yes this is what I wanted but I tried to raise the event in toolbar button but it is not working , I am using inside method handle user command

RAISE EVENT gv_grid->user_command

         EXPORTING

           e_ucomm = 'MC_FC_PRINT_BACK'


Can you give some code snippet for this?

Read only

ThangaPrakash
Active Contributor
0 Likes
3,684

Hello K C,

Refer to the below code.

REPORT  zbmm_zar4021.

*---------------------------------------------------------------------

*  System Name  : SAP R/3

*  Category     : MM

*---------------------------------------------------------------------

* Program Name : ZBMM_ZAR4021

*

* Outline      : Deletion of Info records

*

* Transaction name : ZBMM_0462 - Deletion of Info records

* Type Pools

TYPE-POOLS: slis.

* Constant Declaration used as a flag

CONSTANTS: ct_gc_flag TYPE c VALUE 'X'.

* Global tables

DATA: itab_gt_data TYPE STANDARD TABLE OF zbmm_s0324,

      itab_gt_eina TYPE STANDARD TABLE OF eina,

      itab_gt_eine TYPE STANDARD TABLE OF eine,

      itab_gt_fieldcat TYPE slis_t_fieldcat_alv.

* Workarea

DATA: str_gs_eina TYPE eina,

      str_gs_eine TYPE eine,

      str_gs_layout TYPE slis_layout_alv.

*Selection screen

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: so_lifnr FOR str_gs_eina-lifnr NO INTERVALS,

                so_matnr FOR str_gs_eina-matnr NO INTERVALS,

                so_ekorg FOR str_gs_eine-ekorg NO INTERVALS,

                so_werks FOR str_gs_eine-werks NO INTERVALS,

                so_infnr FOR str_gs_eina-infnr NO INTERVALS,

                so_erdat FOR str_gs_eina-erdat,

                so_exprf FOR str_gs_eine-exprf NO INTERVALS,

                so_inco1 FOR str_gs_eine-inco1 NO INTERVALS.

PARAMETERS: pa_poflg TYPE ILOEE,

            pa_coflg TYPE ILOEA.

SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.

*Create field catalog from dictionary structure or internal table

  PERFORM fm_fieldcat_init.

START-OF-SELECTION.

* Check authorization on transaction

  CALL FUNCTION 'Z_ZBBC_AUTHORITY_TRANSACTION'

    EXPORTING

      i_tcode = 'ZBMM_0462'.

*Select data from tables

  PERFORM fm_select_data.

END-OF-SELECTION.

  IF itab_gt_data IS INITIAL.

*  No data found for Selection Criteria

    MESSAGE s999(zbmm_0001) WITH text-005.

  ELSE.

*    ALV Grid Display

    PERFORM fm_alv_display.

  ENDIF.

*&---------------------------------------------------------------------*

*&      Form  fm_fieldcat_init

*&---------------------------------------------------------------------*

*       text: Used for defining the structure of the ALV

*----------------------------------------------------------------------*

FORM fm_fieldcat_init.

*  Building field catalog

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

      i_program_name        = sy-repid

      i_structure_name      = 'ZBMM_S0324'

      i_inclname            = sy-repid

    CHANGING

      ct_fieldcat           = itab_gt_fieldcat

    EXCEPTIONS

      inconsistent_interface = 1

      program_error         = 2

      OTHERS                = 3.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

ENDFORM.                    "fm_fieldcat_init

*&---------------------------------------------------------------------*

*&      Form  fm_select_data

*&---------------------------------------------------------------------*

*       text: Used for filling respective data from itab_gt_eine and itab_gt_eina table into itab_gt_data table

*----------------------------------------------------------------------*

FORM fm_select_data.

* Workarea

  DATA:  str_ls_data TYPE zbmm_s0324,

        str_ls_eina TYPE eina,

        str_ls_eine TYPE eine.

*  the data is selected from eine into itab_gt_eine.

  SELECT *

  FROM   eine

  INTO TABLE itab_gt_eine

  WHERE infnr IN so_infnr

    AND ekorg IN so_ekorg

    AND werks IN so_werks

    AND loekz EQ pa_poflg

    AND exprf IN so_exprf

    AND inco1 IN so_inco1.

  IF itab_gt_eine IS NOT INITIAL.

*  the data is selected from eina into itab_gt_eina on the basis of info record number in

*  internal table of eine(itab_gt_eine) and respective vendor a/c number, material number

*  and creation dates.

    SELECT *

    FROM   eina

    INTO TABLE itab_gt_eina

    FOR ALL ENTRIES IN itab_gt_eine

    WHERE infnr = itab_gt_eine-infnr

      AND lifnr IN so_lifnr

      AND matnr IN so_matnr

      AND loekz EQ pa_coflg

      AND erdat IN so_erdat.

  ENDIF.

*  the data is stored into an internal table itab_gt_data from itab_gt_eina and itab_gt_eine.

  LOOP AT itab_gt_eina INTO str_ls_eina.

    READ TABLE itab_gt_eine INTO str_ls_eine

    WITH KEY infnr = str_ls_eina-infnr.

    IF sy-subrc EQ 0.

      MOVE: str_ls_eina-matnr TO str_ls_data-matnr,

            str_ls_eina-lifnr TO str_ls_data-lifnr,

            str_ls_eina-erdat TO str_ls_data-erdat,

            str_ls_eina-meins TO str_ls_data-meins,

            str_ls_eina-ernam TO str_ls_data-ernam,

            str_ls_eina-loekz TO str_ls_data-loekz_eina,

            str_ls_eina-infnr TO str_ls_data-infnr,

            str_ls_eine-ekorg TO str_ls_data-ekorg,

            str_ls_eine-werks TO str_ls_data-werks,

            str_ls_eine-esokz TO str_ls_data-esokz,

            str_ls_eine-loekz TO str_ls_data-loekz_eine,

            str_ls_eine-ekgrp TO str_ls_data-ekgrp,

            str_ls_eine-waers TO str_ls_data-waers,

            str_ls_eine-netpr TO str_ls_data-netpr,

            str_ls_eine-peinh TO str_ls_data-peinh,

            str_ls_eine-exprf TO str_ls_data-exprf,

            str_ls_eine-inco1 TO str_ls_data-inco1.

      APPEND str_ls_data TO itab_gt_data.

      CLEAR  str_ls_data.

    ENDIF.

  ENDLOOP.

ENDFORM.                    "fm_select_data

*&---------------------------------------------------------------------*

*&      Form  fm_alv_display

*&---------------------------------------------------------------------*

*       text: For displaying ALV by using table itab_gt_data and adding two buttons for deleting complete info record

*              or deleting purchase view info record from eina or eine table respectively.

*----------------------------------------------------------------------*

FORM fm_alv_display .

*   Workarea

  DATA:str_ls_variant TYPE disvariant. "for parameter IS_VARIANT

  str_ls_variant-report = sy-repid.

  PERFORM fm_populate_layout.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

      i_callback_program      = sy-repid

      i_callback_pf_status_set = 'FM_PFSTATUS'

      i_callback_user_command = 'FM_USERCOMMAND'

*      it_events                = gt_events[]

      is_layout               = str_gs_layout

      it_fieldcat             = itab_gt_fieldcat[]

      i_save                  = 'A'

      is_variant              = str_ls_variant

    TABLES

      t_outtab                = itab_gt_data

    EXCEPTIONS

      program_error           = 1

      OTHERS                  = 2.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

ENDFORM.                    "fm_alv_display

*&---------------------------------------------------------------------*

*&      Form  FM_PFSTATUS

*&---------------------------------------------------------------------*

*       text: For declaring two buttons in GUI status for deleting complete info record

*              or deleting purchase view info record from eina or eine table respectively.

*----------------------------------------------------------------------*

FORM fm_pfstatus USING rt_extab TYPE slis_t_extab.

  SET PF-STATUS 'ZBMM_ZAR4021'.

ENDFORM.                    "FM_PFSTATUS

*&---------------------------------------------------------------------*

*&      Form  FM_USERCOMMAND

*&---------------------------------------------------------------------*

*       text: Form to react according to the user action.

*----------------------------------------------------------------------*

*      -->LV_OKCODE  text: used to capture the function code

*                          of the user-defined push-buttons

*      -->L_SELFIELD text: Holding the lines that are selected.

*----------------------------------------------------------------------*

FORM fm_usercommand USING c_lv_okcode TYPE sy-ucomm str_ls_selfield TYPE slis_selfield.

* Workarea

  DATA:  str_ls_data TYPE zbmm_s0324,

         str_ls_eina TYPE eina,

         str_ls_eine TYPE eine,

         str_ls_reg_eina TYPE eina,

         str_ls_eina_old TYPE eina,

         str_ls_eine_old TYPE eine,

         c_lv_count TYPE integer.

  CASE c_lv_okcode.

* when the info record is double clicked,

* then the transaction me12(change info record) will be called for that record

    WHEN '&IC1'.

      IF str_ls_selfield-fieldname = 'MATNR'.

        READ TABLE itab_gt_data INTO str_ls_data INDEXstr_ls_selfield-tabindex.

          IF sy-subrc EQ 0.

            SET PARAMETER ID 'LIF' field str_ls_data-lifnr.

            SET PARAMETER ID 'MAT' field str_ls_data-matnr.

            SET PARAMETER ID 'EKO' field str_ls_data-ekorg.

            SET PARAMETER ID 'WRK' field str_ls_data-werks.

            SET PARAMETER ID 'INF' field str_ls_data-infnr.

            CALL TRANSACTION 'ME12' AND SKIP FIRST SCREEN.

          ENDIF.

      ENDIF.

*  when the button "Deleting Complete Info Record" is selected,

*  the flag is created in LOEKZ feild of eina table for the respective info record number.

    WHEN 'DCIR'.

      LOOP AT itab_gt_data INTO str_ls_data

        WHERE chk = ct_gc_flag.

          IF str_ls_data-loekz_eina EQ 'X'.

            MESSAGE i610(ZBMM_0001) WITH str_ls_data-infnr.

            CONTINUE.

          ENDIF.

* Read inforecord from eina

        READ TABLE itab_gt_eina INTO str_ls_eina

        WITH KEY infnr = str_ls_data-infnr.

        IF sy-subrc EQ 0.

* Read inforecord from eine

          READ TABLE itab_gt_eine INTO str_ls_eine

          WITH KEY infnr = str_ls_data-infnr.

          IF sy-subrc EQ 0.

            MOVE str_ls_eina TO str_ls_eina_old.

            str_ls_eina-loekz = ct_gc_flag.

          ENDIF.

* Update LOEKZ field in eina

          CALL FUNCTION 'ME_UPDATE_INFORECORD' IN UPDATE TASK

            EXPORTING

              xeina   = str_ls_eina

              xeine   = str_ls_eine

              yeina   = str_ls_eina_old

              yeine   = str_ls_eine

              reg_eina = str_ls_reg_eina.

        ENDIF.

* docu: post conditions (RV_CONDITION_SAVE)

  CALL FUNCTION 'RV_CONDITION_SAVE'.

  CALL FUNCTION 'RV_CONDITION_RESET'

    EXPORTING

      free_memory = 'X'.

* docu:  general (EINA-texts, COMMIT_TEXT)

  CALL FUNCTION 'COMMIT_TEXT'

    EXPORTING

      object = 'EINA'.

    COMMIT WORK.

  IF sy-subrc EQ 0 AND str_ls_data-loekz_eina NE 'X'.

     MESSAGE i608(ZBMM_0001) WITH str_ls_data-infnr.

  ENDIF.

      ENDLOOP.

*  when the button "Deleting Complete Purchase View Record" is selected,

*  the flag is created in LOEKZ feild of eine table for the respective info record number.

    WHEN 'DPVIR'.

      LOOP AT itab_gt_data INTO str_ls_data

        WHERE chk = ct_gc_flag.

          IF str_ls_data-loekz_eine EQ 'X'.

            MESSAGE i612(ZBMM_0001) WITH str_ls_data-infnr.

            CONTINUE.

          ENDIF.

* Read inforecord from eina

        READ TABLE itab_gt_eina INTO str_ls_eina

        WITH KEY infnr = str_ls_data-infnr.

        IF sy-subrc EQ 0.

* Read inforecord from eine

          READ TABLE itab_gt_eine INTO str_ls_eine

          WITH KEY infnr = str_ls_data-infnr.

          IF sy-subrc EQ 0.

            MOVE str_ls_eine TO str_ls_eine_old.

            str_ls_eine-loekz = ct_gc_flag.

          ENDIF.

* Update LOEKZ field in eine

          CALL FUNCTION 'ME_UPDATE_INFORECORD' IN UPDATE TASK

            EXPORTING

              xeina   = str_ls_eina

              xeine   = str_ls_eine

              yeina   = str_ls_eina

              yeine   = str_ls_eine_old

              reg_eina = str_ls_reg_eina.

        ENDIF.

* docu: post conditions (RV_CONDITION_SAVE)

  CALL FUNCTION 'RV_CONDITION_SAVE'.

  CALL FUNCTION 'RV_CONDITION_RESET'

    EXPORTING

      free_memory = 'X'.

* docu:      purchasing organization (EINE-texts, COMMIT_TEXT)

  CALL FUNCTION 'COMMIT_TEXT'

    EXPORTING

      object = 'EINE'.

    COMMIT WORK.

  IF sy-subrc EQ 0 AND str_ls_data-loekz_eina NE 'X'.

    MESSAGE i609(ZBMM_0001) WITH str_ls_eine-infnr.

  ENDIF.

      ENDLOOP.

  ENDCASE.

ENDFORM.                    "FM_USERCOMMAND

*&---------------------------------------------------------------------*

*&      Form  FM_POPULATE_LAYOUT

*&---------------------------------------------------------------------*

*       text: For adding checkboxes in ALV to select multiple data.

*----------------------------------------------------------------------*

FORM fm_populate_layout .

  str_gs_layout-box_fieldname = 'CHK'.

  str_gs_layout-box_tabname = 'ITAB_GT_DATA'.

ENDFORM.                    " FM_POPULATE_LAYOUT

In this program i made two custom buttons and assigned the function code to it.

In your case, remove the function code of standard print button and assign that standard function code

&RNT to your custom button.

Regards,

TP

Read only

0 Likes
3,684

How can I raise ALV toolbar Standard Print event in another custom button

Read only

0 Likes
3,684

Hello KC refer to the demo program "BCALV_TEST_NEUE_FUNCTION" in system where it is explained how they assigned a function code to the button in the ALV toolbar.

Read only

0 Likes
3,684

Hi Thanga,

if someone is asking a question about an ALV class cl_salv_table or in this instance cl_gui_alv_grid, why do you come up with the old school REUSE_ALV_GRID_DISPLAY?

Best,

Sander

Read only

former_member302911
Active Participant
0 Likes
3,685

Pass the Function Code &PRINT to custom button when handle the CL_GUI_ALV_GRID->TOOLBAR Event.

Example:


MOVE '&PRINT'              TO lst_toolbar-function.

MOVE ICON_PRINT      TO lst_toolbar-icon.

MOVE 'Print'                     TO lst_toolbar-quickinfo.

MOVE 'Print'                     TO lst_toolbar-text.


INSERT lst_toolbar        INTO e_object->mt_toolbar INDEX 1.

CLEAR lst_toolbar.

Regards,

Angelo.

Read only

0 Likes
3,684

Thanks Angelo

I can call print event now but problem is it only calls this event , I cannot add further processing to the custom buttom after print command.

I cannot call this method for print 'PRINT_BACKEND' as it is private method of class cl_gui_alv_grid

Read only

0 Likes
3,684

Hi K C,

you can use the events that triggered before and after the execution of the user command to integrate other procedures.

CL_GUI_ALV_GRID->BEFORE_USER_COMMAND

CL_GUI_ALV_GRID->AFTER_USER_COMMAND

Regards,

Angelo.

Read only

0 Likes
3,684

problem solved with CL_GUI_ALV_GRID->AFTER_USER_COMMAND

and Passing  the Function Code &PRINT to custom button


Thanks Angelo

Read only

0 Likes
3,684

Hi

How can i suppress the print dialog box after using standard print functionality in my custom button.

Read only

0 Likes
3,684

For that you have to set the print parameters for Smartform(While calling Smartform). Since it is belongs to SAP name space and the part of a standard class .. i think it will be difficult..

Read only

0 Likes
3,684

guess you have not read the question its not smartform, its an ALV

Read only

0 Likes
3,684

oh ya...

I think you can achieve this by the help of method SET_FRONTEND_PRINT in alv class.

Read only

0 Likes
3,684

call function 'UNSET_PRINTPARAMETER'

      EXPORTING

        NAME                    = space

        IN_PARAMETERS           = ls_pri_params

      IMPORTING

        OUT_PARAMETERS          = ls_pri_params

      EXCEPTIONS

        INVALID_PARAMETER       = 1

        OTHERS                  = 2

             .

   if sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

   endif.


Set Output Device and print immediate = 'X'.

Read only

Karan_Chopra_
Active Participant
0 Likes
3,684

Experts

Is there any way to generate spool after displaying CL_GUI ALV report.

I need to send this spool in PDF via email, so I have added print button functionality in my custom toolbar button as discussed above but I need to suppress print dialog which comes on pressing print button as shown below, how can I do that?

Read only

Former Member
0 Likes
3,684

Hi KC,

You have to disable the standard Print from ALV tool-bar and go for your own customized Print.

Use this code :-

CLASS lcl_event_receiver IMPLEMENTATION.

   METHOD handle_toolbar.

     DATA: ls_toolbar  TYPE stb_button.

* append a separator to normal toolbar

     CLEAR ls_toolbar.

     MOVE 3 TO ls_toolbar-butn_type.

     APPEND ls_toolbar TO e_object->mt_toolbar.

* append an icon to show booking table

     CLEAR ls_toolbar.

     MOVE 'PRINT' TO ls_toolbar-function.

     MOVE icon_print TO ls_toolbar-icon.

     MOVE 'Print'(111) TO ls_toolbar-quickinfo.

     MOVE 'Print'(112) TO ls_toolbar-text.

     MOVE ' ' TO ls_toolbar-disabled.

     APPEND ls_toolbar TO e_object->mt_toolbar.

   ENDMETHOD.

*-------------------------------------------------------------------

   METHOD handle_user_command.

      DATA: lt_rows TYPE lvc_t_row.

     CASE e_ucomm.

       WHEN 'PRINT'.

         CALL METHOD grid1->get_selected_rows

                  IMPORTING et_index_rows = lt_rows.

         CALL METHOD cl_gui_cfw=>flush.

         IF sy-subrc ne 0.

* add your handling, for example

           CALL FUNCTION 'POPUP_TO_INFORM'

                EXPORTING

                     titel = g_repid

                     txt2  = sy-subrc

                     txt1  = 'Error in Flush'(500).

         else.

* any further functionality you want to add

         ENDIF.

     ENDCASE.

   ENDMETHOD.                           "handle_user_command

*-----------------------------------------------------------------

ENDCLASS.


And after the  set_table_for_first_display call its handler


CREATE OBJECT event_receiver.

     SET HANDLER event_receiver->handle_user_command FOR grid1.

     SET HANDLER event_receiver->handle_toolbar FOR grid1.


Hope this piece of code help you.