Announcement

Collapse
No announcement yet.

STRING GRID

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • STRING GRID

    Hallo Miteinander
    Ich versuche grad ein StringGrid zu testen, und bin erstaunt wieviel Quellcode das ding benötigt. Und da ich ein Newbie bin habe ich manches vielleicht total daneben Programmiert. Ich stelle meinen Quellcode hier rein und bitte euch mir verbesserungs Vorschläge mitzuteilen.
    Wie kann ich die beschrifteten Zeilen auf der linken seite einfärben?
    Danke im vorraus Niki

    <PRE>
    procedure TForm1.ColorGridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
    var x : integer;
    r : TRect;
    outRect : TRect;
    Text : String;
    begin
    begin
    with ColorGrid.Canvas do
    begin
    case ARow mod 14 of
    0: Brush.Color := clAqua;
    1: Brush.Color := currZV.currEnterColor;
    2: Brush.Color := clWindow;
    3: Brush.Color := currZV.currEnterColor;
    4: Brush.Color := clWindow;
    5: Brush.Color := currZV.currEnterColor;
    6: Brush.Color := clWindow;
    7: Brush.Color := currZV.currEnterColor;
    8: Brush.Color := clWindow;
    9: Brush.Color := currZV.currEnterColor;
    10: Brush.Color := clWindow;
    11: Brush.Color := currZV.currEnterColor;
    12: Brush.Color := clWindow;
    13: Brush.Color := currZV.currEnterColor;
    14: Brush.Color := clWindow;
    end;
    end;

    if {(ColorGrid.Selection.Left = ACol) and} (ColorGrid.Selection.Top = ARow) then
    begin
    Font.Color := Brush.Color xor 65535;
    if arow = 0 then
    with ColorGrid.Canvas do
    begin{5}
    for x:= 0 to ColorGrid.ColCount-1 do
    begin{6}
    font.Color := clBlack;
    end;{6}
    end;{5}
    end;{4}

    ColorGrid.Canvas.FillRect(Rect);
    DrawText(ColorGrid.Canvas.Handle,
    PChar(ColorGrid.Cells[ACol, ARow]),
    length(ColorGrid.Cells[ACol, ARow]),
    Rect, DT_WordBreak)

    end;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    currZV.currEnterColor := clYellow;
    currZV.currExitColor := clWhite;
    currZV.currFehlerColor := clRed;

    with ColorGrid do
    begin
    RowCount := 14;
    ColCount := 5;
    ColWidths[0] := 60;
    ColWidths[1] := 75;
    ColWidths[2] := 75;
    ColWidths[3] := 75;
    ColWidths[4] := 75;

    RowHeights[0] := 35;
    RowHeights[1] := 18;
    RowHeights[2] := 18;
    RowHeights[3] := 18;
    RowHeights[4] := 18;
    RowHeights[5] := 18;
    RowHeights[6] := 18;
    RowHeights[7] := 18;
    RowHeights[8] := 18;
    RowHeights[9] := 18;
    RowHeights[10] := 18;
    RowHeights[11] := 18;
    RowHeights[12] := 18;
    RowHeights[13] := 18;

    Cells[0,1] := 'Summe';
    Cells[0,2] := 'Jänner';
    Cells[0,3] := 'Februar';
    Cells[0,4] := 'März';
    Cells[0,5] := 'April';
    Cells[0,6] := 'Mai';
    Cells[0,7] := 'Juni';
    Cells[0,8] := 'Juli';
    Cells[0,9] := 'August';
    Cells[0,10] := 'September';
    Cells[0,11] := 'Oktober';
    Cells[0,12] := 'November';
    Cells[0,13] := 'Dezember';
    Cells[1,0] := 'Umsatz in €';
    Cells[2,0] := 'Roherlöse in €';
    Cells[3,0] := 'Stückum satz';
    Cells[4,0] := 'Gewichtsumme in kg';
    end;
    end;

    procedure ColorGridAlignment(Grid: TStringGrid; Rect: TRect; ACol, ARow: Integer; Alignment : TAlignment; Linebreak: Boolean);
    var TextOut : String;
    const SelectedColor = Clblue;
    begin
    Grid.Canvas.FillRect(Rect);
    TextOut := Grid.Cells[ACol,ARow];
    if Linebreak = false then
    begin
    if Alignment = taRightJustify then
    DrawText(Grid.Canvas.Handle, PChar(TextOut),
    StrLen(PChar(TextOut)), Rect,DT_Right);
    end;
    end;

    procedure TForm1.ColorGridSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
    begin
    ShowMessa

  • #2
    Habe was neues gefunden:

    <PRE>
    procedure TForm1.ColorGridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);

    var dx: Integer;
    begin
    with (Sender as TStringGrid) do
    begin
    // Don't change color for first Column, first row
    if (ACol = 0) or (ARow = 0) then
    Canvas.Brush.Color := clSilver
    else
    begin
    case ACol of
    1: Canvas.Font.Color := clBlack;
    2: Canvas.Font.Color := clBlue;
    end;
    // Draw the Band
    if ARow mod 2 = 0 then
    Canvas.Brush.Color := $FFFF00
    else
    Canvas.Brush.Color := $FFFFFF;
    Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
    Canvas.FrameRect(Rect);
    end;
    end;

    // Zeilenumbruch in StringGrid

    ColorGrid.Canvas.FillRect(Rect);
    DrawText(ColorGrid.Canvas.Handle,
    PChar(ColorGrid.Cells[ACol, ARow]),
    length(ColorGrid.Cells[ACol, ARow]),
    Rect, DT_WordBreak)

    end;
    </PRE>

    Aber ich blicke nun nicht ganz durch wie ich den Farbencode auf Gelb ändern kann FFFF00 Funktioniert nicht

    Gruss Nik

    Comment


    • #3
      Hallo,
      <br> bei funktioniert: Canvas.Brush.Color := clYellow;
      <br> mit Delphi5 Gruß ph

      Comment


      • #4
        oooooh *schäm* das hab ich ja noch gar nicht verucht hehe thänxs für den tip .. was hälst du sonst allgemein von meinem quellcode? Betriebsfähig?

        Gruss Niki
        (arbeite mit Delphi6 professionel auf win 2000 professionel

        Comment


        • #5
          Hallo, manchmal hängst halt bei einen immer ab und zu. Das kommt bei mir auch oft vor. Gut das es das Forum gibt ! Kann mir nicht vorstellen das der Code nicht taugt. Funktioniert doch. Gruß ph

          Comment

          Working...
          X