Setting a DBGrid column format in Delphi
14,690
Solution 1
- You can set the
DisplayFormat
of theField
- You can handle
OnGetText
event. This approach allows to do more complex operations with the value.
Solution 2
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 '#.##';
Solution 3
The first port of call is the DisplayFormat of the data field in the database itself.
Comments
-
Blue almost 2 years
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?
-
Blue over 15 yearsI'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?