Posted by Al Peterson on October 08, 2008
In Reply to delphi stringgrid alternating colors posted by Wiona on
October 08, 2008
: dear delphiland team,
: how can I give alternate background colors to the rows of a stringgrid? for
example, colour the even rows in yellow, but leave the fixed row with the titles? (there is no fixed
column). like this:
: title row 0 - normal (silver)
: data row 1 - normal (white)
: data row 2 - yellow
: data row 3 - normal (white)
: data row 4 - yellow
: and so on
: thank you for the great site!
Conditions when to change the background colour:
Even numbered rows: Row mod 2 = 0
Not title row: Row <> 0
Code to change colour:
if (Row mod 0 = 0) and (Row <> 0) then begin Brush.Color := Somecolour; // Paint rectangle of cell Col,Row with Brush.Color; // Write text of cell Col,Row over this background end;
Related articles
Follow Ups