colored string grid lazarus / 7-LCL ---------------------------------------------------------------------- grogh · 2004-05-17 12:38 Hello... How implement color string grid with Lazarus? Thanks ---------------------------------------------------------------------- jesusr · 2004-05-18 02:25 usually you could use the OnDrawCell, for example to draw even rows in blue and odd rows in red, use this code: Code: [Select] procedure TForm1.GridDrawCell(sender as TObject; Col,Row: Integer; aRect: TRect; aState: TGridDrawState) begin   if not (gdfixed in aState) then begin     if Row mod 2 = 0 then begin       Grid.Canvas.Brush.Color := clBlue;     end else begin       Grid.Canvas.Brush.Color := clRed;     end;     Grid.canvas.fillrect(arect);     Grid.canvas.textrect(arect, 0, 0, grid.cells[col,row])   end else begin     // draw fixed grid in a standard way     Grid.defaultdrawcell(col,row,arect,astate);     end; end; since a few days ago, a new event was introduced to do this easily: OnPrepareCanvas so the last example would be: Code: [Select] procedure form1.GridPrepareCanvas(sender as TObject; Col,Row: Integer; aState: TGridDrawState ) begin   if not (gdfixed in aState) then     if Col mod 2 = 0 then begin       Grid.Canvas.Brush.Color := clBlue;     end else begin       Grid.Canvas.Brush.Color := clRed;     end; end; No need to draw anything. I didn't actually check the above examples, they are simply illustrative. ---------------------------------------------------------------------- wile64 · 2006-10-25 19:28 hello, excused me for my bad English, I am user of Lazarus since one years and I would like colored a dbgrid according to criteria's, the example which you function gives well but my system (winXP) is to use has 90%, why? ---------------------------------------------------------------------- quileab · 2006-11-03 11:16 This is my onDrawCell, works fine in my case. Could be used for any StringGrid using (sender as ...) procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;   aRect: TRect; aState: TGridDrawState); const Colores:array[0..3] of TColor=($ffefef, $efffef, $efefff, $efffff); ColSele:array[0..3] of TColor=($444444, $444444, $444444, $444444); begin   if not (gdFixed in aState) then // si no es el tituloŽ   if not (gdSelected in aState) then     begin     (Sender as TStringGrid).Canvas.Brush.Color:=Colores[Row mod 4];     end   else     begin     (Sender as TStringGrid).Canvas.Brush.Color:=ColSele[Row mod 4];     (Sender as TStringGrid).Canvas.Font.Color:=$ffffff;     //(Sender as TStringGrid).Canvas.Font.Style:=[fsBold];     end;   //(Sender as TStringGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);   (Sender as TStringGrid).defaultdrawcell(col,row,arect,astate); end; I hope you can adapt it. Excuse my bad English. Enjoy!