Mega Code Archive

 
Categories / Delphi / Graphic
 

How to get different background color of DBGrid for odd and even rows (2)

Title: How to get different background color of DBGrid for odd and even rows (2) 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;