Hier mal ein Auszug aus meinem Fundus, der wie gewünscht funktioniert:
Delphi-Quellcode:
procedure TForm1.dbgDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
// Zeile mit dem aktiven Datensatz.
if (fdID.AsInteger = dbg.Tag) then begin
dbg.Canvas.Font.Style := [fsBold];
dbg.Canvas.Brush.Color := clLime;
dbg.Canvas.Font.Color := clBlack;
if Copy(fdIP.AsString,1,3) = 'DNS' then begin
if (State = [gdSelected])
or (State = [gdSelected..gdFocused]) then begin
dbg.Canvas.Brush.Color := clNavy;
dbg.Canvas.Font.Color := clRed;
end else begin
dbg.Canvas.Brush.Color := clWhite;
dbg.Canvas.Font.Color := clNavy;
end;
end;
end else begin
dbg.Canvas.Font.Style := [];
end;
// Sonderbehandlung für den Sendernamen
if Column.FieldName = 'Sendername' then begin
if Column.Field.Text = csSenderOhneName then begin
if (State=[gdSelected])
or (State=[gdSelected..gdFocused]) then begin
dbg.Canvas.Brush.Color := clRed;
dbg.Canvas.Font.Color := clWhite;
end else begin
dbg.Canvas.Font.Color := clRed;
end;
end else
if fdSenderName.AsString <> fdSenderTitel.AsString then begin
if (State=[gdSelected])
or (State=[gdSelected..gdFocused]) then begin
dbg.Canvas.Brush.Color := clPurple;
dbg.Canvas.Font.Color := clWhite;
end else begin
dbg.Canvas.Brush.Color := clPurple;
dbg.Canvas.Font.Color := clYellow;
end;
end;
end else
// und noch weitere IF-Elsen
if ...
end;
dbg.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
(Die fd....As... sind persitente Datenbankfelder.)