Advanced Delphi

Moderators: None (Apply to moderate this forum)
Number of threads: 333
Number of posts: 743

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
DBGrid Posted by mac_doggie on 5 Jan 2004 at 4:07 AM
Hi,

I've got a DBGrid in my application. It contains a field that is a currency in the database. In the DBGrid it doesn't show like a currency field. If the value is 2 it should display 2,00 but it just displays 2 If The value is 2,4 it displays 2,4 in stead of 2,40

In other words: I want the DBGRID to display the values with two decimals but I can't seem to figure out how to do this. Can someone tell me please ?



-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...

Report
Re: DBGrid Posted by zibadian on 5 Jan 2004 at 5:09 AM
: Hi,
:
: I've got a DBGrid in my application. It contains a field that is a currency in the database. In the DBGrid it doesn't show like a currency field. If the value is 2 it should display 2,00 but it just displays 2 If The value is 2,4 it displays 2,4 in stead of 2,40
:
: In other words: I want the DBGRID to display the values with two decimals but I can't seem to figure out how to do this. Can someone tell me please ?
:
:
:
: -mac-
: mailto:mac_doggie@hotmail.com
: the Netherlands...
:
:
You could use the OnDrawColumnCell() to draw the currency field the way you want it. If you leave the DefaultDrawing "true", then you only need to worry about that single column.
Report
Re: DBGrid Posted by mac_doggie on 5 Jan 2004 at 7:16 AM
: : Hi,
: :
: : I've got a DBGrid in my application. It contains a field that is a currency in the database. In the DBGrid it doesn't show like a currency field. If the value is 2 it should display 2,00 but it just displays 2 If The value is 2,4 it displays 2,4 in stead of 2,40
: :
: : In other words: I want the DBGRID to display the values with two decimals but I can't seem to figure out how to do this. Can someone tell me please ?
: :
: :
: :
: : -mac-
: : mailto:mac_doggie@hotmail.com
: : the Netherlands...
: :
: :
: You could use the OnDrawColumnCell() to draw the currency field the way you want it. If you leave the DefaultDrawing "true", then you only need to worry about that single column.
:

Could you give me a little piece of example code ? I'm not quite getting it...


-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...


Report
Re: DBGrid Posted by zibadian on 5 Jan 2004 at 9:31 AM
: : : Hi,
: : :
: : : I've got a DBGrid in my application. It contains a field that is a currency in the database. In the DBGrid it doesn't show like a currency field. If the value is 2 it should display 2,00 but it just displays 2 If The value is 2,4 it displays 2,4 in stead of 2,40
: : :
: : : In other words: I want the DBGRID to display the values with two decimals but I can't seem to figure out how to do this. Can someone tell me please ?
: : :
: : :
: : :
: : : -mac-
: : : mailto:mac_doggie@hotmail.com
: : : the Netherlands...
: : :
: : :
: : You could use the OnDrawColumnCell() to draw the currency field the way you want it. If you leave the DefaultDrawing "true", then you only need to worry about that single column.
: :
:
: Could you give me a little piece of example code ? I'm not quite getting it...
:
:
: -mac-
: mailto:mac_doggie@hotmail.com
: the Netherlands...
:
:
:
Here is a quick and untested code, but it should work. The "CurrencyColumn" needs to be changed into whichever value you need.
procedure TForm1.DbGrid1Draw...();
begin
  if DataCol = CurrencyColumn then
    DBGrid1.Canvas.TextRect(Rect, 1, 1, CurrencyToStr(
      DBGrid1.Fields[DataCol].AsCurrency));
end;

For more info on the various method, see the help files.
Report
Re: DBGrid Posted by mac_doggie on 6 Jan 2004 at 2:41 AM
: : : : Hi,
: : : :
: : : : I've got a DBGrid in my application. It contains a field that is a currency in the database. In the DBGrid it doesn't show like a currency field. If the value is 2 it should display 2,00 but it just displays 2 If The value is 2,4 it displays 2,4 in stead of 2,40
: : : :
: : : : In other words: I want the DBGRID to display the values with two decimals but I can't seem to figure out how to do this. Can someone tell me please ?
: : : :
: : : :
: : : :
: : : : -mac-
: : : : mailto:mac_doggie@hotmail.com
: : : : the Netherlands...
: : : :
: : : :
: : : You could use the OnDrawColumnCell() to draw the currency field the way you want it. If you leave the DefaultDrawing "true", then you only need to worry about that single column.
: : :
: :
: : Could you give me a little piece of example code ? I'm not quite getting it...
: :
: :
: : -mac-
: : mailto:mac_doggie@hotmail.com
: : the Netherlands...
: :
: :
: :
: Here is a quick and untested code, but it should work. The "CurrencyColumn" needs to be changed into whichever value you need.
:
: procedure TForm1.DbGrid1Draw...();
: begin
:   if DataCol = CurrencyColumn then
:     DBGrid1.Canvas.TextRect(Rect, 1, 1, CurrencyToStr(
:       DBGrid1.Fields[DataCol].AsCurrency));
: end;
: 

: For more info on the various method, see the help files.
:

I don't get it to work yet.

I inserted this piece of code:
procedure TfrmBank.dbgOverzichtDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin

  if DataCol = 3 then
    dbgOverzicht.Canvas.TextRect(Rect, 1, 1, FloatToStr(
      dbgOverzicht.Fields[DataCol].AsCurrency));

end;


The TextRect doesn't seem to print anything to the screen. The cell stays empty... Any idea why?

By The Way the CurrencyToString function doesn't seem to exist in Delphi 5 so I changed that to FloatToString



-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...


Report
Re: DBGrid Posted by zibadian on 6 Jan 2004 at 5:45 AM
: : : : : Hi,
: : : : :
: : : : : I've got a DBGrid in my application. It contains a field that is a currency in the database. In the DBGrid it doesn't show like a currency field. If the value is 2 it should display 2,00 but it just displays 2 If The value is 2,4 it displays 2,4 in stead of 2,40
: : : : :
: : : : : In other words: I want the DBGRID to display the values with two decimals but I can't seem to figure out how to do this. Can someone tell me please ?
: : : : :
: : : : :
: : : : :
: : : : : -mac-
: : : : : mailto:mac_doggie@hotmail.com
: : : : : the Netherlands...
: : : : :
: : : : :
: : : : You could use the OnDrawColumnCell() to draw the currency field the way you want it. If you leave the DefaultDrawing "true", then you only need to worry about that single column.
: : : :
: : :
: : : Could you give me a little piece of example code ? I'm not quite getting it...
: : :
: : :
: : : -mac-
: : : mailto:mac_doggie@hotmail.com
: : : the Netherlands...
: : :
: : :
: : :
: : Here is a quick and untested code, but it should work. The "CurrencyColumn" needs to be changed into whichever value you need.
: :
: : procedure TForm1.DbGrid1Draw...();
: : begin
: :   if DataCol = CurrencyColumn then
: :     DBGrid1.Canvas.TextRect(Rect, 1, 1, CurrencyToStr(
: :       DBGrid1.Fields[DataCol].AsCurrency));
: : end;
: : 

: : For more info on the various method, see the help files.
: :
:
: I don't get it to work yet.
:
: I inserted this piece of code:
:
: procedure TfrmBank.dbgOverzichtDrawColumnCell(Sender: TObject;
:   const Rect: TRect; DataCol: Integer; Column: TColumn;
:   State: TGridDrawState);
: begin
: 
:   if DataCol = 3 then
:     dbgOverzicht.Canvas.TextRect(Rect, 1, 1, FloatToStr(
:       dbgOverzicht.Fields[DataCol].AsCurrency));
: 
: end;
: 

:
: The TextRect doesn't seem to print anything to the screen. The cell stays empty... Any idea why?
:
: By The Way the CurrencyToString function doesn't seem to exist in Delphi 5 so I changed that to FloatToString
:
:
:
: -mac-
: mailto:mac_doggie@hotmail.com
: the Netherlands...
:
:
:
It could be a color problem; or the code is never called; or the string is empty (which I doubt).
In the first case, you could try to specify another color for the canvas font.
The second problem is easily check using the debugger.
The third problem requires the use of a temp. string, to check if it is filled correctly.
Report
Re: DBGrid Posted by mac_doggie on 6 Jan 2004 at 10:33 AM
: : : : : : Hi,
: : : : : :
: : : : : : I've got a DBGrid in my application. It contains a field that is a currency in the database. In the DBGrid it doesn't show like a currency field. If the value is 2 it should display 2,00 but it just displays 2 If The value is 2,4 it displays 2,4 in stead of 2,40
: : : : : :
: : : : : : In other words: I want the DBGRID to display the values with two decimals but I can't seem to figure out how to do this. Can someone tell me please ?
: : : : : :
: : : : : :
: : : : : :
: : : : : : -mac-
: : : : : : mailto:mac_doggie@hotmail.com
: : : : : : the Netherlands...
: : : : : :
: : : : : :
: : : : : You could use the OnDrawColumnCell() to draw the currency field the way you want it. If you leave the DefaultDrawing "true", then you only need to worry about that single column.
: : : : :
: : : :
: : : : Could you give me a little piece of example code ? I'm not quite getting it...
: : : :
: : : :
: : : : -mac-
: : : : mailto:mac_doggie@hotmail.com
: : : : the Netherlands...
: : : :
: : : :
: : : :
: : : Here is a quick and untested code, but it should work. The "CurrencyColumn" needs to be changed into whichever value you need.
: : :
: : : procedure TForm1.DbGrid1Draw...();
: : : begin
: : :   if DataCol = CurrencyColumn then
: : :     DBGrid1.Canvas.TextRect(Rect, 1, 1, CurrencyToStr(
: : :       DBGrid1.Fields[DataCol].AsCurrency));
: : : end;
: : : 

: : : For more info on the various method, see the help files.
: : :
: :
: : I don't get it to work yet.
: :
: : I inserted this piece of code:
: :
: : procedure TfrmBank.dbgOverzichtDrawColumnCell(Sender: TObject;
: :   const Rect: TRect; DataCol: Integer; Column: TColumn;
: :   State: TGridDrawState);
: : begin
: : 
: :   if DataCol = 3 then
: :     dbgOverzicht.Canvas.TextRect(Rect, 1, 1, FloatToStr(
: :       dbgOverzicht.Fields[DataCol].AsCurrency));
: : 
: : end;
: : 

: :
: : The TextRect doesn't seem to print anything to the screen. The cell stays empty... Any idea why?
: :
: : By The Way the CurrencyToString function doesn't seem to exist in Delphi 5 so I changed that to FloatToString
: :
: :
: :
: : -mac-
: : mailto:mac_doggie@hotmail.com
: : the Netherlands...
: :
: :
: :
: It could be a color problem; or the code is never called; or the string is empty (which I doubt).
: In the first case, you could try to specify another color for the canvas font.
: The second problem is easily check using the debugger.
: The third problem requires the use of a temp. string, to check if it is filled correctly.
:

in the on form create I placed this piece of code and the messagedialog displayed two different values so I'm sure the font color was set. The second Dialog displayed 0 (wich is clBlack) I Also tried Red (255). The property changed alright, but no values where displayed in my DBGrid

  messagedlg(IntToStr(dbgOverzicht.Canvas.Font.Color),mtInformation,[mbOk],0);
  dbgOverzicht.Canvas.Font.Color := clBlack;
  messagedlg(IntToStr(dbgOverzicht.Canvas.Font.Color),mtInformation,[mbOk],0);



I'm sure the code is being executed because I also tried placing a messagedlg in the DrawColumnCell procedure and then I see that the values from the database are filled in(without ,00) and then the field is cleared again.

I really don't know why all this happens, hope you have an answer for me.



-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...


Report
Re: DBGrid property DisplayFormat Posted by Masterijn on 6 Jan 2004 at 11:25 AM
Hallo Nederlanders,
There's a property DisplayFormat on the TNumericField field, I think this can solve your problem in a more global way (for every db-control). On TField there are 2 events OnGetText, OnSetText which also allow you some display control.





Report
Re: DBGrid property DisplayFormat Posted by mac_doggie on 7 Jan 2004 at 3:56 AM
: Hallo Nederlanders,
: There's a property DisplayFormat on the TNumericField field, I think this can solve your problem in a more global way (for every db-control). On TField there are 2 events OnGetText, OnSetText which also allow you some display control.
:
:
:
:
:
:
And how does that work ? Do you have some samplecode perhaps ?

-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.