Change color of DrawGrid Cell lazarus / 39-Graphics ---------------------------------------------------------------------- PeterATC · 2013-07-08 00:52 Hi I am trying to get the color of cells on a draw grid to change color. Below is my code but it does not change the color. procedure TfrmMain.DrawGridDrawCell; var  i, j : integer; begin      for i := 0 to frmMain.drwGrid.ColCount-1 do        for j := 0 to frmMain.drwGrid.RowCount-1 do         begin             frmMain.drwGrid.CellRect(i,j);             frmmain.drwGrid.FocusColor:= ColorOfBricks[i,j];         end; end;    "ColorofBricks"  contains a two dimensional array of TColor values. Any help much appreciated. ---------------------------------------------------------------------- Blaazen · 2013-07-08 01:04 Try OnPrepareCanvas: Code: [Select]procedure TForm1.DrawGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;   aState: TGridDrawState); begin   if aRow = 1     then DrawGrid1.Canvas.Brush.Color := clRed     else DrawGrid1.Canvas.Brush.Color := clGreen; end;This will color all cells to green except cells in the row = 1. You don't have to use loops. Event is triggered for each cell. ---------------------------------------------------------------------- PeterATC · 2013-07-10 02:02 HI that works but I am trying to create a grid with three colors in random bricks. So the color of each cell needs to be read from the colors in the two dimentional array "ColorOfBricks". Is there way to cycle thru each cell and apply the color to the cell. ---------------------------------------------------------------------- taazz · 2013-07-10 02:10 no, cells are not objects per see just positions in the grid to be drawn upon, why don't you use the acol,arow parameters to get the color from the ColorOfBricks array? eg. Code: [Select]procedure TForm1.DrawGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;   aState: TGridDrawState); begin     DrawGrid1.Canvas.Brush.Color := ColorOfBricks[aRow,aCol]; end; ---------------------------------------------------------------------- PeterATC · 2013-07-11 11:54 Thank taazz. It works fine. never thought of using those paramaters.