Autor Beitrag
Bronstein
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Fr 10.11.06 07:01 
Habe mir eine Funktion gebastelt, die mir ein StringGrid mit allen 365 Tagen des Jahres füllt.

Jetzt möchte ich aber die Spalten mit den Samstagen und Sonntagen grau einfärben. Wie mach ich das?

ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
function Wochentag(Datum: TDateTime): string;
begin
  try
    case DayOfWeek(Datum) of
    1: Result := 'So';
    2: Result := 'Mo';
    3: Result := 'Di';
    4: Result := 'Mi';
    5: Result := 'Do';
    6: Result := 'Fr';
    7: Result := 'Sa';
    end;
  except
    Result := '';
  end;
end;


procedure TForm1.FormCreate(Sender: TObject);
var
  i, z: Integer;
  tmpDatum: TDate;
  Tag: String;
begin
  tmpDatum := StrToDate('01.01.' + FormatDateTime('yyyy', now));
  //Spalten einfügen
  for i:=1 to 365 do
  begin
    GridAddCol(1, StringGrid1);
  end;
  StringGrid1.Refresh;
  //Tag Einfügen
  for i:=1 to 365 do
  begin
    //Datum ermitteln
    for z:=1 to 365 do
    begin
      if z = i then
        break;
      tmpDatum:= tmpDatum + 1;
    end;
    StringGrid1.Cells[i, 0]:= FormatDateTime('dd.mm', tmpDatum);
    tmpDatum := StrToDate('01.01.' + FormatDateTime('yyyy', now));
    StringGrid1.ColWidths[i] := 30;
  end;
{  //Samstage und Sonntage markieren
  tmpDatum := StrToDate('01.01.' + FormatDateTime('yyyy', now));
  for z:=1 to 365 do
  begin
    Tag := Wochentag(tmpDatum);
    if (Tag = 'Sa') or (Tag = 'So') then
    begin
      StringGrid1.Canvas.Brush.Color:=EigenschaftenGrid[z,0].Farbe;
    end;
    tmpDatum:= tmpDatum + 1;
  end;   }


end;

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 10.11.06 07:46 
Hallo,

schau dir mal OnDrawCell an, Du findest auch viel dazu im Forum.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Fr 10.11.06 08:38 
Hallo,
danke aber ich habe schon sehr viel gesucht. Habe auch was gefunden wo ich eine Zeile markieren kann und wo ich eine einzelne Zelle markieren kann.

Wie löse ich aber mein Problem.

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 10.11.06 09:23 
Das geht nur über das OnDrawCell, wie user profile iconLannes schon schrieb. Hast Du Dir das schon angesehen?
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Fr 10.11.06 09:34 
Morgen!

Kommt drauf an wie dein Grid aufgebaut ist.
Kannst du mal n Screenshot machen?

Ich würde in der OnDrawCell so vorgehen, das ich mir einfach die Spalten Samstag und Sonntag such und dann für jede Zeile diese Spalte färb.


LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 10.11.06 09:55 
Wenn er eine Titel-Zeile hat, wir dort SA oder SO stehen (oder so ähnlich). Dies kann leicht im OnDrawCell abgefragt werden, da die aktuelle Zeile und Spalte dort bekannt ist. Man muss halt nur Zeile 0 und aktuelle Spalte einsetzen, um den Wochentag zu bekommen.
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Fr 10.11.06 10:00 
so hab ichs ja gemeint user profile iconjasocul
war nur bissl unverständlich ausgedrückt =)

Aber er soll uns erstmal n Screenshot geben, weil er hat ja zig Möglichkeiten sowas darzustellen..

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Fr 10.11.06 10:25 
Hier der Screenshot:
Einloggen, um Attachments anzusehen!
_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Fr 10.11.06 10:36 
interessant..und wo sollen dann deiner meinung nach die Wochentage stehen?
Sag jetzt nicht links =)

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 10.11.06 10:42 
Mal sehen, ob ich meinen Source passend umbasteln kann:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
if Datum(grdKalender.Cells[0,ARow] + Jahr) = Wochenende then // Hier musst Du selbst was machen
begin
  grdKalender.Canvas.Brush.Color := Wochenendfarbe; // Such dir eine Farbe aus
  grdKalender.Canvas.FillRect(Rect);

  // Folgendes brauche ich für einen evtl. selektierten Bereich iirc.
  if (grdKalender.Selection.Left <= ACol) and (grdKalender.Selection.Right >= ACol) and
     (grdKalender.Selection.Top <= ARow) and (grdKalender.Selection.Bottom >= ARow) then
  begin
    grdKalender.Canvas.Brush.Color := TColor(Integer(grdKalender.Canvas.Brush.Color) xor $00FFFFFF);
    grdKalender.Canvas.FrameRect(Rect);
  end;
end;
Das ist relativ alter Source. Ich hoffe, der passt einigermaßen bei Dir.
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Fr 10.11.06 12:26 
Jetzt habe ich die Spalten schon mal markiert. Jetzt steht aber mein Datumswert nicht mehr drin. Hier mal der komplette Code:

ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
function Wochentag(Datum: TDateTime): string;
begin
  try
    case DayOfWeek(Datum) of
    1: Result := 'So';
    2: Result := 'Mo';
    3: Result := 'Di';
    4: Result := 'Mi';
    5: Result := 'Do';
    6: Result := 'Fr';
    7: Result := 'Sa';
    end;
  except
    Result := '';
  end;
end;

procedure GridAddCol (NewColumn: Integer; Grid: TStringGrid);
var
  Column: Integer;
begin
  Grid.ColCount := Grid.ColCount+1;
  for Column := Grid.ColCount-1 downto NewColumn do
    Grid.Cols[Column].Assign(Grid.Cols[Column-1]);
  Grid.Cols[NewColumn-1].Text := '';
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i, z: Integer;
  tmpDatum: TDate;
  Tag: String;
begin
  tmpDatum := StrToDate('01.01.' + FormatDateTime('yyyy', now));
  //Spalten einfügen
  for i:=1 to 365 do
  begin
    GridAddCol(1, StringGrid1);
  end;
  StringGrid1.Refresh;
  //Tag Einfügen
  for i:=1 to 365 do
  begin
    //Datum ermitteln
    for z:=1 to 365 do
    begin
      if z = i then
        break;
      tmpDatum:= tmpDatum + 1;
    end;
    StringGrid1.Cells[i, 0]:= FormatDateTime('dd.mm', tmpDatum);
    tmpDatum := StrToDate('01.01.' + FormatDateTime('yyyy', now));
    StringGrid1.ColWidths[i] := 30;
  end;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  tempDatum: String;
begin
  //Samstage und Sonntage markieren
  if StringGrid1.Cells[ACol,0] <> '' then
  begin
    if (WochenTag(StrToDate(StringGrid1.Cells[ACol,0] + '.2006')) = 'Sa') or (WochenTag(StrToDate(StringGrid1.Cells[ACol,0] + '.2006')) = 'So') then
    begin
      StringGrid1.Canvas.Brush.Color := clGreen;
      StringGrid1.Canvas.FillRect(Rect);
    end;
  end;
end;

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 10.11.06 12:50 
Zwei Möglichkeiten:
1. Du lässt die erste Zeile gar nicht einfärben, oder
2. Du machst StringGrid1.Canvas.TextOut die Textausgabe selbst.
Die Parameter von TextOut habe ich grade nicht im Kopf. Aber es gibt ja die Delphi-Hilfe.
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Fr 10.11.06 12:58 
ausblenden Delphi-Quelltext
1:
textout(rect.left+2, rect.top+2, cells[ACol, ARow]);					


Wenn ichs richtig im Kopf hab

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Fr 10.11.06 13:14 
Moin :-)

Die Erstellung des StringGrids mit 366 Spalten erscheint mir doch etwas 'kompliziert' und das Beschriften der 1.Reihe auch :gruebel:
Denkanstoß:
ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  tmpDatum: TDate;
begin
  aktJahr := FormatDateTime('yyyy', Date);    //aktJahr als public
  tmpDatum := StrToDate('01.01.' + aktJahr);  //'StartDatum'
  StringGrid1.ColCount := 366;                //max. Spaltenanzahl

  //--Spalten beschriften 
  for i:=0 to Pred(StringGrid1.ColCount) do
  begin
     StringGrid1.Cells[i, 0]:= FormatDateTime('dd.mm', tmpDatum);
     StringGrid1.ColWidths[i] := 30;
     tmpDatum:= tmpDatum + 1;
  end;
end;

//--Zelle zeichnen
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  tempDatum: String;
begin
  //Samstage und Sonntage markieren
  if StringGrid1.Cells[ACol,ARow] <> '' then
  begin
      tempDatum := StrToDate(Format('%s.%s',[StringGrid1.Cells[ACol,ARow], aktJahr]));
      //--wenn Tagesnummer 1=Sonntag oder 7=Samstag, dann Zelle grün malen, ansonsten mit der StringGridfarbe 
      if DayOfWeek(tempDatum) in [1,7] then
        StringGrid1.Canvas.Brush.Color := clGreen
      else
        StringGrid1.Canvas.Brush.Color := StringGrid1.Color;

      //-- Zellenhintergrund malen
      StringGrid1.Canvas.FillRect(Rect);
      //--Textausgeben
      StringGrid1.Canvas.TextOut(Rect.Left+2,Rect.Top+2,StringGrid1.Cells[ACol,ARow] );
    end;
end;
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: Fr 10.11.06 18:54 
So jetzt funktioniert das mal soweit.

Jetzt habe ich aber schon das nächste Problem. Bei mir geht jetzt das Multiselect nicht mehr. Obwohl das doch standardmäßig eingestellt ist.

Hier mal der aktuelle Code:
ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  tmpDatum: TDate;
begin
  aktJahr := FormatDateTime('yyyy', Date);    //aktJahr als public
  aktJahr := '.' + aktJahr;
  tmpDatum := StrToDate('01.01' + aktJahr);  //'StartDatum'
  StringGrid1.ColCount := 366;                //max. Spaltenanzahl
  //--Spalten beschriften
  for i:=1 to Pred(StringGrid1.ColCount) do
  begin
     StringGrid1.Cells[i, 0]:= FormatDateTime('dd.mm', tmpDatum);
     StringGrid1.ColWidths[i] := 30;
     tmpDatum:= tmpDatum + 1;
  end;
end;

Function IsInt(s1:String):Boolean;
var
  i:Integer;
Begin
  Result := true;
  If Length(s1) > 0 Then Begin
    For i := 1 to Length(s1) do Begin
      If not (s1[i] in ['0'..'9']) Then Begin
        Result := false;
        Break;
      End;
    End;
  End Else Result := false;
End;

function IsDate(s:String): Boolean;
//Format dd.mm.yyyy
begin
  if IsInt(s[1]) and (IsInt(s[2])) and (IsInt(s[4])) and (IsInt(s[5])) and (IsInt(s[7])) and (IsInt(s[8])) and (IsInt(s[9])) and (IsInt(s[10])) then
    result:= true
  else
    result:=false;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  tempDatum: TDate;
begin
  //Samstage und Sonntage markieren
  if (IsDate(StringGrid1.Cells[ACol,0]+ aktJahr)) or (StringGrid1.Cells[ACol,ARow] <> '') then
  begin
    tempDatum := StrToDate(StringGrid1.Cells[ACol,0] + aktJahr);
    if DayOfWeek(tempDatum) in [1,7] then
      StringGrid1.Canvas.Brush.Color := clGray
    else
      StringGrid1.Canvas.Brush.Color := StringGrid1.Color;
  end
  else
    StringGrid1.Canvas.Brush.Color := StringGrid1.Color;

  //-- Zellenhintergrund malen
  StringGrid1.Canvas.FillRect(Rect);
  //--Textausgeben
  StringGrid1.Canvas.TextOut(Rect.Left+2,Rect.Top+2,StringGrid1.Cells[ACol,ARow] );

end;


Wenn ich den Code von DrawCell weglasse geht mein multiselect. Wie kann man das lösen

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 10.11.06 23:51 
Hallo,

das Multiselect geht schon, nur du siehst es nicht mehr.
Man muss die Selection in OnDrawCell gesondert berücksichtigen.

Dabei hilft Dir die Variable State die von OnDrawCell zur Verfügung gestellt wird.

In etwa so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if gdSelected in State then
  //zeichne selectierte Zelle
  else
   //zeichne nicht selectierte Zelle

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 11.11.06 09:02 
Ich hatte das mal so gelöst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
    if (grdKalender.Selection.Left <= ACol) and (grdKalender.Selection.Right >= ACol) and
       (grdKalender.Selection.Top <= ARow) and (grdKalender.Selection.Bottom >= ARow) then begin
      grdKalender.Canvas.Brush.Color := TColor(Integer(grdKalender.Canvas.Brush.Color) xor $00FFFFFF);
      grdKalender.Canvas.FrameRect(Rect);
    end;
Ist aus dem selben alten Source, wie oben.
Bronstein Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 578
Erhaltene Danke: 1

WIN XP
Delphi 6 / Delphi 2006 / Delphi XE
BeitragVerfasst: So 12.11.06 00:27 
Ja danke das fuktioniert auch so einigermaßen.

Ich möchte jetzt aber auch zellen markieren können die nicht durchgehen sind.

Sprich ich möchte z.B. mit Hilfe der STRG-Taste die Zellen [0, 1] und [2, 5] selektieren. Das geht leider noch nicht

_________________
Es gibt keine dummen Fragen nur dumme Antworten!!!