Weil die festen Spalten niemals den Status
gdSelected
haben?
Und wenn du den Code
richtig formatierst, dann sieht man auch etwas klarer:
Delphi-Quellcode:
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;
Du setzt an
drei Stellen immer
StringGrid1.Canvas.Font.Color := clblack;
. Wozu das?
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;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ea 0a 4c 14 0d b6 3a a4 c1 c5 b9
dc 90 9d f0 e9 de 13 da 60)