Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi DB Grid - 1. Spalte einfärben (https://www.delphipraxis.net/101722-db-grid-1-spalte-einfaerben.html)

Svenkan 17. Okt 2007 22:28


DB Grid - 1. Spalte einfärben
 
Hallo!
Gibt es wie im Datagrid irgendwie die Möglichkeit, die jeweils 1. Spalte wie die Titelzeile einzufärben?

quendolineDD 17. Okt 2007 22:34

Re: DB Grid - 1. Spalte einfärben
 
Meinst du Sowas wie
Delphi-Quellcode:
StringGrid.FixedCols
Oder die 1. Spalte in eine bestimmte Farbe färben
Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
with (sender as tStringGrid) do
  if ACol = 0 then
  begin
   Canvas.Brush.Color := clRed;
   Canvas.FillRect(Rect);
   Canvas.TextOut(Rect.Left+2, Rect.Top+2, (sender as tstringgrid).Cells[ACol, ARow]);
  end;
end;
Ups, seh gerade es ging um DB-Grid und nicht StringGrid :wall: :oops:

Svenkan 17. Okt 2007 22:49

Re: DB Grid - 1. Spalte einfärben
 
Genau sowas!
Nur für's DB Grid. ;)

/edit: hehe, jep. :)

Svenkan 17. Okt 2007 22:58

Re: DB Grid - 1. Spalte einfärben
 
Hab jetzt folgenden Code gefunden und modifiziert:

Delphi-Quellcode:
procedure TVertretungen.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
 if Column.FieldName = 'KLASSEN' then begin
      DBGrid1.Canvas.Brush.Color := clGradientActiveCaption;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
 end;
end;
Nun möchte ich, dass in dieser Spalte auch fett geschrieben wird:

Delphi-Quellcode:
      DBGrid1.Canvas.Font.Style := [fsBold];
Das eingefügt bewirkt leider so überhaupt nichts. :(

/edit:

Delphi-Quellcode:
procedure TVertretungen.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
 if Column.FieldName = 'KLASSEN' then begin
      DBGrid1.Canvas.Brush.Color := clGradientActiveCaption;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      DBGrid1.Canvas.Font.Style := [fsBold];
      DBGrid1.Canvas.TextRect(Rect,Rect.Left, Rect.Top,Column.Field.AsString);
 end;
end;
Mit dem Code funktionierts!


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:33 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz