Einzelnen Beitrag anzeigen

Piethan

Registriert seit: 2. Jun 2008
Ort: Köln
43 Beiträge
 
Delphi XE Architect
 
#3

AW: DBgrid Farbe setzten

  Alt 23. Dez 2011, 15:32
Ich weiß nicht was du machen möchtest, aber so färbe ich einzelne Zellen.

Delphi-Quellcode:
procedure Tfrm.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
    if (State * [gdSelected, gdFocused, gdFixed] = []) then
  begin
    // Hintergrund des Feldes Status einfärben
    if (Column.Field.FieldName='TYP') then
    begin
      case Column.Field.AsInteger of
       1: DBGrid1.Canvas.Brush.Color := clYellow;
       3: DBGrid1.Canvas.Brush.Color := clSkyBlue;
       4: DBGrid1.Canvas.Brush.Color := clteal;
      end;
    end;
    if (Column.Field.FieldName='KORREKT') then
    begin
      case Column.Field.AsInteger of
       1: DBGrid1.Canvas.Brush.Color := clBlack;
      end;
    end;

    if (Column.Field.FieldName='STORNO') then
    begin
      if (Column.Field.AsInteger > 0) then
        DBGrid1.Canvas.Brush.Color := clRed;
    end;

    if (Column.Field.FieldName='KOSTENLOS') then
    begin
      if (Column.Field.AsInteger > 0) then
        DBGrid1.Canvas.Brush.Color := clRed;
    end;

    {
    // Schriftfarbe des Feldes EATyp setzen
    if (Column.Field.FieldName='EATyp') then
    begin
      case Column.Field.AsInteger of
      1: DBGrid1.Canvas.font.Color := clYellow;
      3: DBGrid1.Canvas.font.Color := clGreen;
      4: DBGrid1.Canvas.font.Color := clRed;
      end;
      DBGrid1.Canvas.font.Style := DBGrid1.Canvas.font.Style + [fsBold];  // fett
    end;}


    DBGrid1.Canvas.fillRect( rect );
  end;
  DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State); // Text ausgeben lassen
end;
  Mit Zitat antworten Zitat