| Autor |
Beitrag |
AlexII
      
Beiträge: 180
|
Verfasst: Mo 07.01.08 01:44
Ich will aus einem StringGrid das gespeicherte Datum laden, es mit dem aktuellen Datum vergleichen und wenn es mehr als 14 Tage sind die entsprechende Zeile grün färben.
Jetzt das Problem: Irgendwie klappt der Code nicht, er will nicht richtig färben und die Schrift befindet sich was weiß ich wo.
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
| begin for f:=1 to StringGrid1.RowCount-2 do begin DateTimePicker2.Date:=StrToDate(Stringgrid1.cells[5,f]); DateTimePicker3.Date:=Now; tage:=Round(DateTimePicker3.Date - DateTimePicker2.Date); ACol:=0; ARow:=f; if (tage>=14) and (tage<21) then begin Canvas.Brush.Color:=RGB(0,255,0); Canvas.FillRect(Rect); Canvas.Font.Color:=RGB(0,0,0); -> Canvas.TextOut(Rect.Left+2, Rect.Top+2, StringGrid1.Cells[ACol, ARow]); ????????? end; end; |
|
|
Narses
      

Beiträge: 10185
Erhaltene Danke: 1261
W11x64
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mo 07.01.08 02:06
Moin!
In welcher Methode steht der Code (wer ruft ihn auf)?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
AlexII 
      
Beiträge: 180
|
Verfasst: Mo 07.01.08 12:13
Es steht hier:
Delphi-Quelltext 1: 2: 3: 4: 5:
| procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin
end; |
|
|
Narses
      

Beiträge: 10185
Erhaltene Danke: 1261
W11x64
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mo 07.01.08 13:05
Moin!
Füg´ das mal ein:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
| begin for f:=1 to StringGrid1.RowCount-2 do begin DateTimePicker2.Date:=StrToDate(Stringgrid1.cells[5,f]); DateTimePicker3.Date:=Now; tage:=Round(DateTimePicker3.Date - DateTimePicker2.Date); ACol:=0; ARow:=f; if (tage>=14) and (tage<21) then with StringGrid1 do begin Canvas.Brush.Color:=RGB(0,255,0); Canvas.FillRect(Rect); Canvas.Font.Color:=RGB(0,0,0); -> Canvas.TextOut(Rect.Left+2, Rect.Top+2, StringGrid1.Cells[ACol, ARow]); ????????? end; end; |
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Lannes
      
Beiträge: 2352
Erhaltene Danke: 4
Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
|
Verfasst: Mo 07.01.08 13:43
Hallo,
@ Narses: Denke das die Schleife innerhalb OnDrawCell das größere Problem ist.
Das OnDraw Cell-Ereignis wird für jede Zelle ausgelöst die gezeichnet werden muss.
In den Variablen Rect, ACol und ARow der Ereignisbehandlungsmethode sind die aktuellen Zellkoordinaten enthalten. Diese aktuelle Zelle muss Dein Code prüfen bzw. zeichnen.
Pseudocode:
Quelltext 1: 2: 3:
| >> ist aktuelle Spalte = Index 5, dann >> ist aktuelle Zeile im Bereich der Datum-Zellen, dann >> prüfe Datum und Zeichne entsprechend |
 Merken:
In OnDrawCell keine Zelle -außer der aktuellen Zelle- beeinflussen, Ausnahme zeichnen über mehrere Zellen.
_________________ MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
|
|
AlexII 
      
Beiträge: 180
|
Verfasst: Mo 07.01.08 14:01
Ich hab's, ich hab's:
Hier wird allerdings nur eine Celle gefärbt, weißt jemand vielleicht wie ich die ganze Zeile färbe?
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
| procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var f, tage: Integer; begin for f:=1 to StringGrid1.RowCount-2 do begin DateTimePicker2.Date:=StrToDate(Stringgrid1.cells[5,f]); DateTimePicker3.Date:=Now; tage:=Round(DateTimePicker3.Date - DateTimePicker2.Date);
if (ACol=0) and (ARow=f) and (tage>=14) and (tage<21) then begin StringGrid1.Canvas.Brush.Color:=RGB(0,255,0); end else if (ACol=0) and (ARow=f) and (tage>=21) and (tage<28) then begin StringGrid1.Canvas.Brush.Color:=RGB(0,0,255); end else if (ACol=0) and (ARow=f) and (tage>=28) then begin StringGrid1.Canvas.Brush.Color:=RGB(255,0,0); end; StringGrid1.Canvas.FillRect(rect); StringGrid1.Canvas.TextOut(Rect.Left+2, Rect.Top+2, StringGrid1.Cells[ACol, ARow]); end; end; |
|
|
passiv
      
Beiträge: 270
WIN XP Professional
Delphi 7 Enterprise, Java (Eclipse), Python 2.5, Django 1.1
|
Verfasst: Mo 07.01.08 15:16
AlexII hat folgendes geschrieben: | | ...weißt jemand vielleicht wie ich die ganze Zeile färbe? |
naja...
meinst du, der Rand der entsteht beim FillRect soll verschwinden?
-> dann: FillRect(Rect(rect.left-1,rect.top-1,rect.width+2,rect.height+2));
ich weiß jetzt nicht, was zuerst kommt, left oder top bzw. width oder height
_________________ Die Probleme, die es in der Welt gibt, sind nicht mit der gleichen Denkweise zu lösen, die sie erzeugt hat.
Albert Einstein
|
|
Lannes
      
Beiträge: 2352
Erhaltene Danke: 4
Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
|
Verfasst: Mo 07.01.08 15:41
Hallo,
werf endlich die Schleife weg
Außerdem schließt du mit if (ACol=0) alle anderen Spalten aus.
Hier mal ein Ansatz, Fehlerbehandlung bzgl. gültiges Datum fehlt noch.
Eventuell musst Du auch noch ein Neuzeichnen des Grids erzwingen, liegt dran wie/wann die Daten in das Grid kommen.
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
| procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var iTage : Integer; s : String; begin with StringGrid1 do if ARow in [FixedRows..RowCount-2] then begin iTage := Round(Trunc(now) - StrToDate(Cells[5,ARow])); if iTage > 13 then begin case iTage of 14..20 : Canvas.Brush.Color := clAqua; 21..27 : Canvas.Brush.Color := clYellow; else Canvas.Brush.Color := clNochNeFarbe; end; Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]); end; end; end; |
_________________ MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
|
|
AlexII 
      
Beiträge: 180
|
Verfasst: Mo 07.01.08 20:21
Ok, hab deine Lösung übernommen 
|
|
|