![]() |
Datenbank: ABS-db • Version: 5.12 • Zugriff über: ABSQuery
DisplayFormat+TStringGridanzeige
Hallo,
im AfterOpen der Query habe ich den Code:
Delphi-Quellcode:
Dieser bewirkt leider nicht die gewünschte Anzeige des Betrages mit Nachkommastellen.
with DataSet.FieldByName('VKnetto') as TNumericField do
DisplayFormat := '#.###.##0.00'; Wer hilft bitte? Gruß Lombi |
Re: DisplayFormat+TStringGridanzeige
Hallo Lombi,
nur der erste Punkt wird als Dezimaltrennzeichen erkannt:
Delphi-Quellcode:
Freundliche Grüße
with DataSet.FieldByName('VKnetto') as TNumericField do
DisplayFormat := '#,###,##0.00'; |
Re: DisplayFormat+TStringGridanzeige
Danke marabu,
aber im Grid steht immer noch 1 statt 1,00 Wie bitte löse ich das? |
Re: DisplayFormat+TStringGridanzeige
Wenn das Eingabefeld den Fokus hat, dann wird EditFormat statt DisplayFormat nicht verwendet.
Hast du den Cursor mal in ein anderes Feld gesetzt? |
Re: DisplayFormat+TStringGridanzeige
Ja, das habe ich.
Bei mir findet keine direkte Eingabe im Grid statt. Vielleicht hängt das mit onDrawCell des Grids zusammen? |
Re: DisplayFormat+TStringGridanzeige
Zitat:
|
Re: DisplayFormat+TStringGridanzeige
In der ABSTabelle ist alles richtg dargestellt, im Grid werden die Nullen unterschlagen!
Also muß im OnDrawCell des Grid noch irgendetwas für DisplayFormat hinzugefügt werden. |
Re: DisplayFormat+TStringGridanzeige
Wie zeichnest du die Zellen?
|
Re: DisplayFormat+TStringGridanzeige
Delphi-Quellcode:
...
// Zelle einfärben if (ARow < FixedRows) or (ACol < FixedCols) then Canvas.Brush.Color := clBlue else if (ARow = Row) and (ACol >= FixedCols) then Canvas.Brush.Color := clYellow else Canvas.Brush.Color := clWhite; Canvas.FillRect(Rect); |
Re: DisplayFormat+TStringGridanzeige
Ruf mal die default Drawmethode auf.
|
Re: DisplayFormat+TStringGridanzeige
Meinst Du DefaultDrawing?
|
Re: DisplayFormat+TStringGridanzeige
Ja
|
Re: DisplayFormat+TStringGridanzeige
DefaultDrawing: True/False
Da tut sich leider nichts! |
Re: DisplayFormat+TStringGridanzeige
Hallo,
am onDrawCell hängt es vermutlich auch nicht. Strings werden im Grid schon mit Nullen dargestellt. Ist vielleicht die folgende Zuweisung nicht korrekt?
Delphi-Quellcode:
Warum werden dabei im Grid die Nullen nach dem Komma nicht gezeigt?
QueryArt.FieldByName('VKNetto').AsFloat := StrToFloat(EdVKNet.Text);
Wer hilft bitte weiter? Gruß Lombi |
Re: DisplayFormat+TStringGridanzeige
Hallo Lombi,
wenn du beim Ereignis OnDrawCell() den Feldwert des DataSet für die Ausgabe bereit stellst, dann solltest du nicht Field.AsString verwenden. Versuche es mal mit Field.DisplayText. Freundliche Grüße |
Re: DisplayFormat+TStringGridanzeige
Hallo marabu,
super 100 Punkte für dich! Zum Abschluß noch eine Frage: Statt "Currency" in der Tabelle kann ich doch solche Werte auch als Float deklarieren oder? Viele Grüße Lombi |
Re: DisplayFormat+TStringGridanzeige
Du meinst wegen deiner vier Nachkommastellen? Niemand kann dich davon abhalten.
Schönes Wochenende |
Re: DisplayFormat+TStringGridanzeige
... muß doch noch eine Frage nachschieben:
Wie erreiche ich, dass die Beträge im Grid alle rechtsbündig angezeigt werden? Bei unterschiedlich langen Werten sieht das optisch nicht besonders gut aus. Auch dir ein schönes Wochenende! Gruß Lombi |
Re: DisplayFormat+TStringGridanzeige
Zitat:
Ich würde den Wert formatiert anzeigen lassen |
Re: DisplayFormat+TStringGridanzeige
marabu hatte in der Zwischenzeit die Lösung.
Hast du einen Tipp, wie ich im Grid die Beträge rechtsbündig darstellen kann? |
Re: DisplayFormat+TStringGridanzeige
Setzte das Alignment dementsprechend.
|
Re: DisplayFormat+TStringGridanzeige
Meinst du so etwas?
Delphi-Quellcode:
Bei StringGrid gibt es kein Alignment.
EdVKnet.SetAlignment(taRightJustify);
|
Re: DisplayFormat+TStringGridanzeige
Dann hilft Selberzeichnen. DefaultDrawing auf false und OnDrawCell z.B. so etwas:
Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); var s: string; R: TRect; begin if (ACol >= StringGrid1.FixedCols) and (ARow >= StringGrid1.FixedRows) then begin R := Types.Rect(Rect.Left, Rect.Top,Rect.Right - 2,Rect.Bottom - 2); s := StringGrid1.Cells[ACol,ARow]; DrawText(StringGrid1.Canvas.Handle,PChar(s),-1, R,DT_RIGHT or DT_BOTTOM or DT_SINGLELINE); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:00 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