Setting a DBGrid column format in Delphi
Asked Answered
D

3

6

I am using a DBGrid component in Delphi. I wonder how I can set the format of a column. I have real values that I want to be displayed as currency in the grid.

Someone knows how?

Discuss answered 16/10, 2008 at 14:1 Comment(1)
possible duplicate of How to Format a DBGrid Column to Display Two Decimal Places?Fervency
B
9
  1. You can set the DisplayFormat of the Field
  2. You can handle OnGetText event. This approach allows to do more complex operations with the value.
Banky answered 16/10, 2008 at 14:41 Comment(0)
Z
5

If you don't add the fields to field Editor list you can get the formating by code as :

TFloatField(MyQuery.fieldByName('MyField').DisplayFormat := '0.00';

if you don't want to show the zeros replace '0.00' with '#.##';

Zama answered 16/10, 2008 at 21:36 Comment(0)
C
2

The first port of call is the DisplayFormat of the data field in the database itself.

Clown answered 16/10, 2008 at 14:8 Comment(1)
I've set the column type to decimal(20,2) in my old MySql 4.1 database. Trailing zeros are not shown in the DBGrid. Is there something else to set?Discuss

© 2022 - 2024 — McMap. All rights reserved.