Get different background color of DBGrid for odd and even rows (Another way)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
uses // ... Grids, DBGrids, db //... procedure artgrid(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); //... implementation //... procedure TForm1.artgrid(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if ((Sender as tdbgrid).DataSource.DataSet.RecNo mod 2) = 0 then (Sender as tdbgrid).Canvas.Brush.Color := clblue; //or any color (Sender as tdbgrid).DefaultDrawColumnCell(rect, datacol, column, state); end; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // for all DrawColumnCell event of DBGrid in any Form (here "Form2"): procedure TForm2.DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin Form1.artgrid(Sender, Rect, DataCol, Column, State); end; |