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: 

Check box color in alv grid

Former Member
0 Kudos

Hi friends,

My requirement is , i am displaying data in alv grid with check box,here i want when we select check box then that realated line should be appear in the Blue color,can any one support me , Thanku in advance

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

FORM user USING lv_okcode LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

data wa_final like gt_final.

  • assign the function code to variable v_okcode

lv_okcode = sy-ucomm.

  • CASE sy-ucomm.

  • handle the code execution based on the function code encountered

CASE lv_okcode.

loop at gt_final into wa_finalwhere chk = 'X'.

wa_final-line_color = 'C111' .

modify gt_final from wa_final index sy-tabix transporting line_color.

clear wa_final.

endloop.

ENDFORM.

Ram.

11 REPLIES 11

Former Member
0 Kudos

Hi,

Add one more column to your final internal table, line_color type c length 4.

Make use of info_fieldname property of ALV layout i.e. wa_layout-info_fieldname = 'LINE_COLOR'.

Once you check on the check box, in the USER-COMMAND event set the line color of that row i.e. wa_final-line_color = 'C110' and modify the internal table.

Regards,

Danish.

0 Kudos

Hi danish,

Thanku for the reply,but i doesnt work ,can u observe this code and give me your suggestion eloborately.

gwa_fldcat-col_pos = 2.

gwa_fldcat-fieldname = 'CHK'.

gwa_fldcat-tabname = 'GT_FINAL'.

  • gwa_fldcat-EMPHASIZE = 'C310'.

  • gwa_fldcat-input = 'X'.

gwa_fldcat-edit = 'X'.

gwa_fldcat-checkbox = 'X'.

gwa_fldcat-just = 'C'.

gwa_fldcat-key = 'X'.

gwa_fldcat-outputlen = 16.

gwa_fldcat-seltext_l = 'Selection'.

APPEND gwa_fldcat TO git_fldcat.

CLEAR gwa_fldcat.

FORM build_catalog .

gs_layout-colwidth_optimize = 'X'.

gs_layout-zebra = 'CHK'.

gs_layout-info_fieldname = 'LINE_COLOR'.

  • gs_layout-box_fieldname = 'CHK'.

gs_layout-box_tabname = 'GT_FINAL-CHK'.

ENDFORM. " BUILD_CATALOG

&----


*& Form USER

&----


FORM user USING lv_okcode LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

  • assign the function code to variable v_okcode

lv_okcode = sy-ucomm.

  • CASE sy-ucomm.

  • handle the code execution based on the function code encountered

CASE lv_okcode.

loop at gt_final where chk = 'X'.

gt_final-line_color = 'C110' .

endloop.

WHEN 'EXECUTE'.

PERFORM execute.

WHEN 'SELECTALL'.

PERFORM selectall.

WHEN 'DESELCTALL'.

PERFORM deselectall.

WHEN 'ASCENDING'.

PERFORM ascending.

WHEN 'DESCENDING'.

PERFORM descending.

ENDCASE.

PERFORM alv.

ENDFORM.

0 Kudos

Hi,

I cannot see any modifications to internal table after setting the line color !

Danish.

0 Kudos

Sorry Danish, I didn't understand what you said,can you say elaborately

0 Kudos

u need to use .

DATA : ref_grid TYPE REF TO cl_gui_alv_grid,

     CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

       IMPORTING

         e_grid = ref_grid.

then use,

    CALL METHOD ref_grid->check_changed_data.

this method modify your table for all changes. including checkboxes.

loop at table where checkbox is not initial.

table-line_color = 'C610' " red

modify table.

endloop.

then refresh alv with

rs_selfield-refresh = 'X'.

take care.

Çağatay

0 Kudos

Hi,

After assigning the line color, u have to modify the internal table. You are simple looping that internal table and assigning color on checked values to the work area.

You will have to use MODIFY itab (If your internal table has a header line) OR MODIFY itab FROM wa.

Danish.

0 Kudos

Thanku my friends , but not solved.

Former Member
0 Kudos

Hi,

FORM user USING lv_okcode LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

data wa_final like gt_final.

  • assign the function code to variable v_okcode

lv_okcode = sy-ucomm.

  • CASE sy-ucomm.

  • handle the code execution based on the function code encountered

CASE lv_okcode.

loop at gt_final into wa_finalwhere chk = 'X'.

wa_final-line_color = 'C111' .

modify gt_final from wa_final index sy-tabix transporting line_color.

clear wa_final.

endloop.

ENDFORM.

Ram.

0 Kudos

Depending in the ALV you're using, try extend your output tabel with a nested table that holds the style attributes for each cell.

example.


types:  begin of ty_output..
            .....your fields... whatever...
types:    celltab type lvc_t_styl.   " < extra styles itab for each cell/field
types:  end of ty_output.


data: it_output type table of ty_output.
data: wa_output type ty_output.

Then you do:


  data: lt_celltab type lvc_t_styl.
  data: ls_celltab type lvc_s_styl.

  loop at it_output into wa_output.

    clear lt_celltab.

    ls_celltab-fieldname = FIELD1'.
    ls_celltab-style = '00000087'. "<== color red
    insert ls_celltab into table lt_celltab.
    ls_celltab-fieldname = 'FIELD2'.
    ls_celltab-style = '00000087'.
    insert ls_celltab into table lt_celltab.
" ... and so for each field...
    insert ls_celltab into table lt_celltab.


    insert lines of lt_celltab into table wa_output-celltab.

    modify it_output from wa_output..
  endloop.

and


gs_layout-stylefname = 'CELLTAB'.

.

0 Kudos

Thanku very much Ram prasad - -

v

0 Kudos

Hi,

Try this.



  CASE r_ucomm.
    WHEN '&IC1'.
      READ TABLE it_final INTO wa_final INDEX rs_selfield-tabindex.
      IF sy-subrc = 0.
        CASE rs_selfield-fieldname.
          WHEN 'CHECK'.
            rs_selfield-refresh = 'X'.
            IF wa_final-check = 'X'.
              wa_final-check = ' '.
              wa_final-line_color = ' '.
            ELSE.
              wa_final-check = 'X'.
              wa_final-line_color = 'C310'.
            ENDIF.
            MODIFY it_final FROM wa_final INDEX sy-tabix.
        ENDCASE.
      ENDIF.
  ENDCASE.

Regards,

Danish