Setting a DBGrid column format in Delphi

2019-02-22 06:47发布

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?

3条回答
啃猪蹄的小仙女
2楼-- · 2019-02-22 06:56

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

查看更多
迷人小祖宗
3楼-- · 2019-02-22 07:05
  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.
查看更多
三岁会撩人
4楼-- · 2019-02-22 07:07

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

查看更多
登录 后发表回答