DBGrid coloring problem lazarus / 16-Databases ---------------------------------------------------------------------- piper62 · 2007-11-14 06:12 Hi, I have a problem in coloring of a DBGrid. I can set with the following code the font color but the background of the cells isn't changed. v_color is set on Form.Show to an initial state of clBlack. procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;   DataCol: Integer; Column: TColumn; State: TGridDrawState); begin    v_buffer_new:=ZQuery1.FieldByName('md_row_date').AsString;    if ZQuery1.Active then    begin       if v_buffer_new=v_buffer_old then       begin          DBGrid1.Canvas.Font.Color:=v_color;          DBGrid1.Canvas.Brush.Color:=clSilver;          DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);       end       else       begin          if v_color=clBlack then v_color:=clBlue          else v_color:=clBlack;          DBGrid1.Canvas.Font.Color:=v_color;          DBGrid1.Canvas.Brush.Color:=clBlack;          DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);          v_buffer_old:=v_buffer_new;       end;    end; end; The complete thing is running under Lazarus 0.9.22 with FP 2.0.4 on Debian Linux with GTK1. Has somebody an idea why only the font is changed? Help appreciated. Regards, Tibor ---------------------------------------------------------------------- Leledumbo · 2007-11-14 08:40 Why don't you change color property of dbgrid in the object inspector? I have no problem changing the color of the background from there. Well, I don't know if it's a bug of Lazarus 0.9.22 or not, but I guess it's better to try 0.9.23 with fpc 2.2.0. At least, upgrade the fpc, 2.2.0 is a stable release. ---------------------------------------------------------------------- jesusr · 2007-11-14 17:49 The problem is that DefaultDrawColumnCell only draws text (layout, color etc), if you use OnDrawColumnCell you should also draw cell background. From your code it looks like you want to do custom drawing but only to change font and cell color, There are 2 ways to fix this, one is using DBGrid1.canvas.FillRect(aRect); to clear the draw background using the canvas brush, or (better IMO) to use OnPrepareCanvas, there you only change canvas attributes and don't need to actually draw anything, you need to remove OnDrawColumnCell though. ---------------------------------------------------------------------- piper62 · 2007-11-14 23:15 thanx for the hints! Now it works with DBGrid1.canvas.FillRect(Rect); with the code the bevaviour of the DBGrid is now as I wanted it to have. It's a medical application where this modul shows documentation lines regarding to the patient. and there can be MANY of them over the time. so it becomes difficult to have a good overview about the documentation if there's no differentiation between lines which belong to the same date. So, the Grid no changes the color of the lines where the date changes so that the physician sees on one view the documentation lines which belong together. Thanx again! Tibor