AGB  ·  Datenschutz  ·  Impressum  







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

2 Stellen im Stringgrid

Ein Thema von Hansa · begonnen am 28. Dez 2003 · letzter Beitrag vom 11. Mär 2004
 
grayfox

Registriert seit: 22. Jan 2003
Ort: Litschau
173 Beiträge
 
Delphi 4 Standard
 
#17

Re: 2 Stellen im Stringgrid

  Alt 10. Mär 2004, 20:37
hallo hansa!
sieh dir das mal an:

Delphi-Quellcode:
procedure TAuftragDlg.PosGridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  CellText: String;
  tw: ShortInt;
  Zahlwert: Double;
begin
  with Sender as TStringGrid do begin
    if not (gdFixed in State) then begin
      if (aRow mod 2 = 0) then begin
        Canvas.Brush.Color:= $00FDFACE;
        Canvas.Font.Color:= clBlack
      end else begin
        Canvas.Brush.Color:= $00CEFFFD;
        Canvas.Font.Color:= clBlack
      end
    end else begin
      Canvas.Brush.Color:= clBtnFace;
      Canvas.Font.Color:= clBlack;
    end;

    CellText:= trim(Cells[aCol,aRow]);

    if (aRow > 0) and (aCol in [0,4..17]) then begin
      try
        if CellText= 'then
          Zahlwert:= 0
        else
          Zahlwert:= StrToFloat(CellText);
        case aCol of
          4,7,8,9,12,15 : FNumberFormat:= '#';
          5 : FNumberFormat:= '#0.000';
          6,10,11,13,14,16,17: FNumberFormat:= '#,##0.00';
        end;

        if Zahlwert > 0 then
          CellText:= FormatFloat(FNumberFormat,ZahlWert)
            else
          CellText:= '';
      except
        CellText:= '';
      end;
    end;

    if Cells[1,aRow] = ' - then
      Cells[1,aRow]:= '';
    if Cells[1,aRow] <> 'then begin
      tw:= Canvas.TextWidth(CellText);
      Canvas.FillRect(Rect);

      if (aRow = 0) then
        Canvas.TextOut(Rect.Left + (Rect.Right-Rect.Left-tw) div 2, Rect.Top+2, CellText)
      else if aCol in [0,4..17] then
        Canvas.TextOut(Rect.Right -2 - tw, Rect.Top + 2, CellText)
      else
        Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, CellText);
    end;
  end;
end;
hier gehts um ein stringgrid mit einer ganzen menge spalten, mit 3 verschiedenen zahlenformaten.
das ganze wird dann noch entweder links, rechts oder mittig ausgerichtet.

vielleicht ist es etwas umständlich geschrieben, aber es funktioniert

mfg, stefan
  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 02:11 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-2025 by Thomas Breitkreuz