Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a DBGrid column format in Delphi

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?

like image 616
Blue Avatar asked Oct 16 '08 14:10

Blue


3 Answers

  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.
like image 118
Germán Estévez -Neftalí- Avatar answered Sep 25 '22 11:09

Germán Estévez -Neftalí-


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 '#.##';

like image 30
Mohammed Nasman Avatar answered Sep 24 '22 11:09

Mohammed Nasman


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

like image 39
mj2008 Avatar answered Sep 25 '22 11:09

mj2008