Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

DBGrid

mac_doggiemac_doggie Member Posts: 488
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...

Comments

  • zibadianzibadian Member Posts: 6,349
    : 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.
  • mac_doggiemac_doggie Member Posts: 488
    : : 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...


  • zibadianzibadian Member Posts: 6,349
    : : : 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.
    [code]
    procedure TForm1.DbGrid1Draw...();
    begin
    if DataCol = CurrencyColumn then
    DBGrid1.Canvas.TextRect(Rect, 1, 1, CurrencyToStr(
    DBGrid1.Fields[DataCol].AsCurrency));
    end;
    [/code]
    For more info on the various method, see the help files.
  • mac_doggiemac_doggie Member Posts: 488
    : : : : 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.
    : [code]
    : procedure TForm1.DbGrid1Draw...();
    : begin
    : if DataCol = CurrencyColumn then
    : DBGrid1.Canvas.TextRect(Rect, 1, 1, CurrencyToStr(
    : DBGrid1.Fields[DataCol].AsCurrency));
    : end;
    : [/code]
    : 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:
    [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;
    [/code]

    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...


  • zibadianzibadian Member Posts: 6,349
    : : : : : 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.
    : : [code]
    : : procedure TForm1.DbGrid1Draw...();
    : : begin
    : : if DataCol = CurrencyColumn then
    : : DBGrid1.Canvas.TextRect(Rect, 1, 1, CurrencyToStr(
    : : DBGrid1.Fields[DataCol].AsCurrency));
    : : end;
    : : [/code]
    : : 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:
    : [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;
    : [/code]
    :
    : 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.
  • mac_doggiemac_doggie Member Posts: 488
    : : : : : : 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.
    : : : [code]
    : : : procedure TForm1.DbGrid1Draw...();
    : : : begin
    : : : if DataCol = CurrencyColumn then
    : : : DBGrid1.Canvas.TextRect(Rect, 1, 1, CurrencyToStr(
    : : : DBGrid1.Fields[DataCol].AsCurrency));
    : : : end;
    : : : [/code]
    : : : 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:
    : : [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;
    : : [/code]
    : :
    : : 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

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

    [/code]

    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...


  • MasterijnMasterijn Member Posts: 188
    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.





  • mac_doggiemac_doggie Member Posts: 488
    : 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...


Sign In or Register to comment.