![]() |
StringGrid Zeile einfärben
Hallo,
was ist hier falsch am Code? :shock: leider bekomme ich auch keine Fehlermeldung ?
Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); var c : TColor; begin if StringGrid1.Cells[3,Arow]='1' then c:=clYellow else if StringGrid1.Cells[3,Arow]='2' then c:=clFuchsia else if StringGrid1.Cells[3,Arow]='3' then c:=clRed; if gdSelected in State then c:=clred; StringGrid1.Canvas.FillRect(Rect); StringGrid1.Canvas.Font.Color:=clBlack; StringGrid1.Canvas.TextRect(Rect,Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow]); end; |
AW: StringGrid Zeile einfärben
Welchen Wert hat c wenn keine der Bedingungen erfüllt ist? Und wo wird c verwendet?
|
AW: StringGrid Zeile einfärben
Leider bekommen wir auch keine Beschreibung was passiert, bzw. was nicht passiert und was eigentlich passieren sollte.
Zitat:
Zitat:
|
AW: StringGrid Zeile einfärben
Liste der Anhänge anzeigen (Anzahl: 1)
Danke für Eure Hilfe :)
Es geht jetzt!!
Delphi-Quellcode:
Noch eine Zusatzfrage, (siehe Bild) wieso wird die erste Spalte mit eingefärbt? Beim selektieren nicht!
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); begin if StringGrid1.Cells[3,Arow]='1' then begin StringGrid1.Canvas.Brush.Color := clYellow; StringGrid1.Canvas.Font.Color := clblack; end else if StringGrid1.Cells[3,Arow]='2' then StringGrid1.Canvas.Brush.Color := clred; StringGrid1.Canvas.Font.Color := clblack; if gdSelected in State then StringGrid1.Canvas.Brush.Color := clred; StringGrid1.Canvas.Font.Color := clblack; StringGrid1.Canvas.FillRect(Rect); StringGrid1.Canvas.Font.Color:=clBlack; StringGrid1.Canvas.TextRect(Rect,Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow]); end; |
AW: StringGrid Zeile einfärben
Weil die festen Spalten niemals den Status
Delphi-Quellcode:
haben?
gdSelected
Und wenn du den Code richtig formatierst, dann sieht man auch etwas klarer:
Delphi-Quellcode:
Du setzt an drei Stellen immer
procedure TForm1.StringGrid1DrawCell( Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState );
begin if StringGrid1.Cells[3, ARow] = '1' then begin StringGrid1.Canvas.Brush.Color := clYellow; StringGrid1.Canvas.Font.Color := clblack; end else if StringGrid1.Cells[3, ARow] = '2' then StringGrid1.Canvas.Brush.Color := clred; StringGrid1.Canvas.Font.Color := clblack; if gdSelected in State then StringGrid1.Canvas.Brush.Color := clred; StringGrid1.Canvas.Font.Color := clblack; StringGrid1.Canvas.FillRect( Rect ); StringGrid1.Canvas.Font.Color := clblack; StringGrid1.Canvas.TextRect( Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow] ); end;
Delphi-Quellcode:
. Wozu das?
StringGrid1.Canvas.Font.Color := clblack;
Das macht exakt das Gleiche:
Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell( Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState );
begin StringGrid1.Canvas.Font.Color := clblack; if StringGrid1.Cells[3, ARow] = '1' then begin StringGrid1.Canvas.Brush.Color := clYellow; end else if StringGrid1.Cells[3, ARow] = '2' then StringGrid1.Canvas.Brush.Color := clred; if gdSelected in State then StringGrid1.Canvas.Brush.Color := clred; StringGrid1.Canvas.FillRect( Rect ); StringGrid1.Canvas.TextRect( Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow] ); end; |
AW: StringGrid Zeile einfärben
Oder noch kürzer:
Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell( Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState );
begin StringGrid1.Canvas.Font.Color := clblack; if (gdSelected in State) or (StringGrid1.Cells[3, ARow] = '2') then StringGrid1.Canvas.Brush.Color := clRed else if StringGrid1.Cells[3, ARow] = '1' then StringGrid1.Canvas.Brush.Color := clYellow; StringGrid1.Canvas.FillRect( Rect ); StringGrid1.Canvas.TextRect( Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow] ); end; |
AW: StringGrid Zeile einfärben
Vielen Dank für die erfolgreiche Hilfe hier im Forum! 8-)
Wenn ich jetzt noch ein Icon aus einer ImageList hinzufügen möchte, muss ich was beachten? Dieses hier funktioniert leider nicht!
Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); var X, Y: Integer; begin StringGrid1.Canvas.Font.Color := clblack; if StringGrid1.Cells[3, ARow] = '1' then begin StringGrid1.Canvas.Brush.Color := clYellow; ImageList1.Draw(StringGrid1.Canvas, X, Y, 0, true); // Was ist hier falsch? end else if StringGrid1.Cells[3, ARow] = '2' then StringGrid1.Canvas.Brush.Color := clgray; if gdSelected in State then StringGrid1.Canvas.Brush.Color := clred; StringGrid1.Canvas.FillRect( Rect ); StringGrid1.Canvas.TextRect( Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow] ); end; |
AW: StringGrid Zeile einfärben
Wie sind denn die Werte von X und Y? Du deklarierst zwar die Variablen, weißt diesen aber keine Werte zu. Somit sind die undefiniert und können irgendwo in einem negativen Bereich liegen. Auch hier hast du die Compiler Meldung nicht beachtet. Der schreibt nämlich genau das hin.
Weise also den beiden Variablen einen Wert zu und schon müsste das funktionieren. Hier vielleicht noch ein Tipp. ![]() ![]() ![]() |
AW: StringGrid Zeile einfärben
Zitat:
Zitat:
Zitat:
|
AW: StringGrid Zeile einfärben
hallo,
dieses funktioniert leider auch nicht!
Delphi-Quellcode:
var
X, Y: Integer; begin if StringGrid1.Cells[3, ARow] = '1' then begin StringGrid1.Canvas.Brush.Color := clYellow; X := Rect.Left; Y := Rect.Top; ImageList1.Draw(StringGrid1.Canvas, X, Y, 0, true); { 0 = erstes Image in ImageList } end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:49 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