AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TStringGrid, Sortier-Pfeil anzeigen

Ein Thema von hoika · begonnen am 28. Aug 2006 · letzter Beitrag vom 19. Mär 2007
 
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.276 Beiträge
 
Delphi 10.4 Sydney
 
#9

Re: TStringGrid, Sortier-Pfeil anzeigen

  Alt 19. Mär 2007, 10:14
Hallo,

override ist dein Freund.

FCellPropertiesForDrawCell ist eine Event,
welches vom jeweiligen Form wissen will,
wie eine Zelle angezeigt werden soll.

Es entspricht also in etwa dem alten OnDrrawCell.

Das könnte man auch direkt über die Komponente lösen,
indem eine Liste für die Überschrift (z.B. alles zentriert)
und für die einzelnen Spalten/Zeilen geführt wird.
Dabie muss dann aber auch der Zustand "Zelle markiert"
extra mit gespeichert werden (oder die invertierst die Zellenfarbe).

Ich habe das deswegen nicht so weitergemacht,
weil bei einigen meiner Grids noch in Abhängigkeit der Zeile verschiedene Farben
benutzt werden sollten.
Die Spalten-Id alleine reichte halt nicht aus.
Also habe uich das über das per CellPropertiesForDrawCell gemacht.



Heiko


Delphi-Quellcode:

{ cell properties for <TCellPropertiesForDrawCell> }
type
  TCellProperties = record
   { alignment }
    Alignment: TAlignment;

   { column is the sort column }
    bColIsSortCol: Boolean;
   { asc order }
    bAscOrder : Boolean;

   { font properties }
    Font: record
      Color: TColor;
    end;

   { brush properties }
    Brush: record
      Color: TColor;
    end;
  end; { TCellProperties }


protected
    FCellPropertiesForDrawCell : TCellPropertiesForDrawCell;


     procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
       AState: TGridDrawState); override;


procedure TEditGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
  AState: TGridDrawState);
begin
  if DefaultDrawing then
    Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2, Cells[ACol, ARow]);
  inherited DrawCell(ACol, ARow, ARect, AState);


  if Assigned(FCellPropertiesForDrawCell) then
  begin
    FCellProperties.Alignment := taLeftJustify;
    FCellProperties.Font.Color := Self.Font.Color;
    FCellProperties.Brush.Color := Self.Brush.Color;
    FCellProperties.bColIsSortCol := False;
    FCellProperties.bAscOrder := True;

    if (gdSelected in AState) then
    begin
      FCellProperties.Brush.Color := clActiveCaption;
      FCellProperties.Font.Color := clWhite;
    end
    else
    begin
      FCellProperties.Font.Color := Self.Font.Color;
    end;

    FCellPropertiesForDrawCell(Self,
      ACol, ARow, ARect, AState, FCellProperties);

    InternalDrawCell(ACol, ARow,
      ARect, AState, FCellProperties);
  end;
end;



procedure TEditGrid.InternalDrawCell(ACol, ARow: Longint;
  ARect: TRect; AState: TGridDrawState;
  const theCellProperties: TCellProperties);
var
  c: TCanvas;
begin
  c:= Self.Canvas;

  if ARow<FixedRows then
  begin
    c.Brush.Color:= FixedColor;
  end
  else
  begin
    c.Brush.Color := theCellProperties.Brush.Color;
  end;

  c.Font.Color := theCellProperties.Font.Color;

  c.FillRect(ARect);
  Inc(ARect.Top,2);

  if theCellProperties.Alignment=taCenter then
  begin
    Inc(ARect.Left,2);

    if theCellProperties.bColIsSortCol then
    begin
      ARect.Right:= ARect.Right-16;
    end;

    DrawText(c.Handle, PChar(Cells[ACol,ARow]),
      Length(Cells[ACol,ARow]), ARect,
      DT_END_ELLIPSIS or DT_CENTER or DT_NOPREFIX);

    if theCellProperties.bColIsSortCol then
    begin
      ARect.Right:= ARect.Right+16;
    end;
  end; { if theCellProperties.Alignment=taCenter then }

  if theCellProperties.bColIsSortCol then
  begin
    if theCellProperties.bAscOrder then
    begin
      c.Draw(ARect.Right-15,((ARect.Bottom-ARect.Top) div 2)-6,PicUp);
    end
    else
    begin
      c.Draw(ARect.Right-15,((ARect.Bottom-ARect.Top) div 2)-6,PicDown);
    end;
  end;

 { right alignment }
  if theCellProperties.Alignment=taRightJustify then
  begin
    Dec(ARect.Right,2);

    DrawText(c.Handle, PChar(Cells[ACol,ARow]),
      Length(Cells[ACol,ARow]), ARect,
      DT_END_ELLIPSIS or DT_RIGHT or DT_NOPREFIX);
  end;

 { left alignment }
  if theCellProperties.Alignment=taLeftJustify then
  begin
    Inc(ARect.Left,2);

    DrawText(c.Handle, PChar(Cells[ACol,ARow]),
      Length(Cells[ACol,ARow]), ARect,
      DT_END_ELLIPSIS or DT_NOPREFIX);
  end;
end; { TEditGrid.InternalDrawCell }
Heiko
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:35 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 by Thomas Breitkreuz