DBGrid 中的显示-数字用千分位来显示

今天看到别人用 DBGrid 做的显示数据时数据的格式为 11,097.44  ,而一般的是 11097.44 ,这个 ","是怎

么加上去的呢?我首先想到的是用 OnGetText 这个事件,于是就去查看这个程序的源码,都看了一遍,怎么没

有这个 onGetText 的事件呢?肯定没有用这个事件,那是怎么用得呢?详细的分析,噢,找到了,是永久字段

的 DisplayFormat 的属性在控制. 可是我不爱用永久字段,怎么办呢?好说,试试  Table1.FieldByName('字

段名').DisplayFormat = '###,###.###';
,错了,没有这个 DisplayFormat 的属性,怎么会没有呢?再看看源码,原来 DisplayFormat 是永久字段才

有的属性
TAggregateField,TDateTimeField,TNumericField,TSQLTimeStampField
从上面这四个字段类型才有 DisplayFormat 属性,知道这个了,把程序这样改就行了
db.TBCDField(table1.FieldByName('buyin_amt')).DisplayFormat := '###,###.###';
这样也行,
db.TNumericField(table1.FieldByName('buyin_amt')).DisplayFormat := '###,###.###';
因为 TBCDField 继承自 TNumericField 字段,如果对字段的继承不怎么明白,在设计时添加不同的永久字段
然后就很容易的看到是从哪继承来的.


附 delphi 帮助中对 DisplayFormat 的解释(本人的英语水平很差,所有就一个词一个词的译吧,不会的词用

金山词霸译)

Determines how a numeric field's value is formatted for display in a data-aware control.

怎么使一个数字类型的字段值按某种格式在数据感知控件中显示

property DisplayFormat: String;

Description

Use the DisplayFormat property to override automatic formatting of a field for display purposes.

依照某种意图(purposes)来显示时要使用 DisplayFormat 属性来覆盖一个字段的自动显示格式

Note: DisplayFormat affects only the display of the field's data. It does not affect the

注意:   DisplayFormat 仅仅影响这个字段数据的显示 , 它不会影响有效性,比如使用 asString 把一个
validity of strings assigned to a numeric field using the AsString property.

string 赋给一个数字类型的字段。

the value of DisplayFormat is a string that encodes the formatting of numeric data using the

isplayFormat 的值是一个字符串,它的数字数据的编码格式使用


specifiers in the following table:

下面表格中指定的


Specifier Represents ( 描述 )

0 Digit placeholder. If the value being formatted has a digit in the position where the "0"

appears in the format string, then that digit is copied to the output string. Otherwise, a "0" is

stored in that position in the output string.
0   是一个数字占位符,如果一个数据中有一个数字在 格式字符中‘0’的位置出现,则把 该数字复制到这个位置,    否则,会以 0 来添充这个位置.
# Digit placeholder. If the value being formatted has a digit in the position where the "#"

appears in the format string, then that digit is copied to the output string. Otherwise, nothing

is stored in that position in the output string.
 #   指原样显示

. Decimal point. The first "." character in the format string determines the location of

the decimal separator in the formatted value; any additional "." characters are ignored. The

actual character used as a the decimal separator in the output string is determined by the

DecimalSeparator global variable. The default value of DecimalSeparator is specified in the

Number Format of the Regional Settings section in the Windows Control Panel.
 这是一个十进制的分隔符,只能有一个,多余的就会忽略

, Thousand separator. If the format string contains one or more "," characters, the output

will have thousand separators inserted between each group of three digits to the left of the

decimal point. The placement and number of "," characters in the format string does not affect

the output, except to indicate that thousand separators are wanted. The actual character used as

a the thousand separator in the output is determined by the ThousandSeparator global variable.

The default value of ThousandSeparator is specified in the Number Format of the Regional Settings

section in the Windows Control Panel.

 千分位的分隔符

E+ Scientific notation. If any of the strings "E+", "E-", "e+", or "e-" are contained in the

format string, the number is formatted using scientific notation. A group of up to four "0"

characters can immediately follow the "E+", "E-", "e+", or "e-" to determine the minimum number

of digits in the exponent. The "E+" and "e+" formats cause a plus sign to be output for positive

exponents and a minus sign to be output for negative exponents. The "E-" and "e-" formats output

a sign character only for negative exponents.

'xx'/"xx" Characters enclosed in single or double quotes are output as-is, and do not

affect formatting.
; Separates sections for positive, negative, and zero numbers in the format string.

The locations of the leftmost "0" before the decimal point in the format string and the rightmost

"0" after the decimal point in the format string determine the range of digits that are always

present in the output string.

The number being formatted is always rounded to as many decimal places as there are digit

placeholders ("0" or "#") to the right of the decimal point. If the format string contains no

decimal point, the value being formatted is rounded to the nearest whole number.

If the number being formatted has more digits to the left of the decimal separator than there are

digit placeholders to the left of the "." character in the format string, the extra digits are

output before the first digit placeholder.

The following table shows the effect of various format strings:

DisplayFormat Value Result Comment

#.## 12.2 12.2 Note extra digit to left of decimal still appears
#.00 2.5 2.50 Note extra zero: field will always show two decimal places
00.## .006 00.01 Note extra 0s to right of decimal point and rounding to two decimal

places.

To allow different formats for positive, negative, and zero values, the format string can contain

between one and three sections separated by semicolons.

One section: The format string applies to all values.
 Two sections: The first section applies to positive values and zeros, and the second

section applies to negative values.
 Three sections: The first section applies to positive values, the second applies to

negative values, and the third applies to zeros.

If the section for negative values or the section for zero values is empty, that is, if there is

nothing between the semicolons that delimit the section, the section for positive values is used

instead.

If the section for positive values is empty, or if the entire format string is empty, the value

is formatted using general floating-point formatting with 15 significant digits. General

floating-point formatting is also used if the value has more than 18 digits to the left of the

decimal point and the format string does not specify scientific notation.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、 DBGridEh(增强型表格组件)功能详解.....................................................................4 二、应用实例..........................................................................................................................5 1. 定制标题行......................................................................................................................5 1) 制作复杂标题行.......................................................................................................5 2) 按钮式标题..............................................................................................................5 3) 标题行显示图片.......................................................................................................5 4) 如根据不同状态在数据单元格显示相应图片...................................................5 5) 自动显示标题行的升降排序标志(▽降序△升序)并做相应排序...............6 6) 点dbgrideh 标题排序..............................................................................................7 7) 在DBGridEH 怎样实现多重排序(标题出现0123等排列序号)? ................ 11 8) 让dbgrid显示序号................................................................................................ 11 2. 外观布局........................................................................................................................12 1) 根据不同字段显示相应的小图片.....................................................................12 2) 显示检查框(checkbox)外观.............................................................................12 3) 显示单、多列下拉列表.........................................................................................12 4) 显示日历下拉列表.................................................................................................13 5) 3D或平面外观效果...............................................................................................13 6) 行头和列头的启用关闭.........................................................................................13 7) DBGrid如何实现透明效果?.................................................................................13 8) 滚动条的各种应用.................................................................................................16 9) 数据行高................................................................................................................19 10) DBGrid设置Rowheight后如何将单元格内容纵向和垂直都居?..............19 11) 设置DBGridEH 自适应列宽的最好方法.........................................................20 12) Ehlib 的DBGridEh首列加序号........................................................................21 13) 分行分列、单元格的颜色设置.........................................................................23 14) 点击不同单元格列,执行不同的动作.............................................................27 15) 下拉式计算器.....................................................................................................28 16) 鼠标移到某个单元格,指针形状改变.............................................................28 17) 自动填充网格列宽到网格客户区.....................................................................29 18) 从注册表或ini文件保存或恢复网格和列的层次。...................................29 3. 编辑功能........................................................................................................................29 1) 多选........................................................................................................................29 2) 文本多行显示.........................................................................................................30 3) 显示备注字段.........................................................................................................30 4) 如何让dbgrideh1 显示数据时只显示两位小数...................................................30 5) 获得当前DBGridEh表单元格的序号.............................................................30 6) 怎样在dbgridEh和Edit显示金额的千分号...................................................30 7) end;请问怎么才能使DBGridEh不滚动就能提交数据?...................................32 8) 我怎么把dbgrid 里的数据一次插入到数据库呢................................................32 9) 在DBGrid可选行而又可进入编辑状态......................................................32 10) 修正DBGrideh 丢失焦点时自动关闭输入法的问题......................................35 11) DBGRIDEH选定多行删除怎么实现...............................................................36 12) DBGrid 滚动表格的代码...................................................................................37 4. 统计功能........................................................................................................................37 白波九道整理自用版 第 3 页 1) 页脚合计................................................................................................................37 2) 定制表格底部(footer)区域的汇总统计行.......................................................38 3) TDBSumList说明..................................................................................................38 4) 如何工作以及为什么有时SumList的集合值计算不正确?.............................39 5) dbgrideh列求和.....................................................................................................39 5. 数据功能........................................................................................................................40 1) 查找字段点击某列值的下拉按纽弹出一个从数据库取值下拉列表...............40 2) 使用DBGridEh自动过滤实现方法.....................................................................40 3) 使用DBGridEh自动过滤实现方法2 ..................................................................41 4) DBGridEh 控件使用过滤功能 (适用ehlib 5.2 ehlib 5.3)................................42 5) 支持模糊查询.........................................................................................................43 6) ehlib4.4.50支持模糊匹配的修改方法..............................................................44 7) EhLib 5.0 Build 5.0.13的过滤字串都是模糊过滤修改.......................................45 8) 滚动条滚动时选择不变,还有自动过滤功能的实现.........................................45 9) 增量搜索................................................................................................................46 10) ehlib总是按两次ctrl+f才出来查找框,怎么办?.........................................46 11) 如何改良dbgrideh的文字过滤........................................................................46 12) 改进DBGrideh 表头点击自动排序,实现双击状态轮流.................................47 13) 改良Ehlib 的排序功能,加快排序速度.............................................................49 14) 在DbGridEh显示TreeView效果................................................................50 15) DBGridEh-KeyList、PickList............................................................................51 16) 主从表设置........................................................................................................53 17) 在DbGridEh显示表..............................................................................55 6. 输入/输出.......................................................................................................................56 1) 导入导出数据.........................................................................................................56 2) 从多种格式导入/导出数据到TDBGridEh...........................................................57 3) DBGRID 生成EXCEL报表.................................................................................57 4) 使用TPrintDBGridEh 组件.................................................................................61 5) 打印时确定Ehlib定义的报表表头颜色? ............................................................61 6) Ehlib 的PrintDBGridEh如何印页码,即第几页共几页...................................62 7) 怎么让PrintDBGridEh只打印DbGridEh 指定的列.......................................62 8) 怎样进行横向打印/ 打印预览?........................................................................62 7. 将存在的DBGrid组件转换为DBGridEh组件...........................................................62 三、EhLib安装问题.............................................................................................................64 1. EhLib 安装步骤.............................................................................................................64 2. EhLib 安装问题(dbsumlst.dcu出错) ..........................................................................64 3. 安装提示找不到.BPL文件...........................................................................................65 四、Delphi 下的优秀表格(Grid)显示控件........................................................................65 1. NextGrid .........................................................................................................................65 2. TopGrid 3.01...................................................................................................................65 3. XLGrid............................................................................................................................66 4. DevExpress ExpressQuantumGrid .................................................................................66 5. TMS Grid Pack...............................................................................................................68 6. EhLib ..............................................................................................................................71 白波九道整理自用版 第 4 页 7. ProfGrid..........................................................................................................................71 8. EasyGrid .........................................................................................................................71 五、delphi 配置文件的使用(*.ini).........................................................................71 六、窗口动画效果Animatewindow应用...........................................................................72 七、Delphi Excel to Sql Server..............................................................................................73 八、Delphi控制Excel的经验如下:..................................................................................76
要在 Delphi 7 的 DBGrid 控件的每行数据显示一个按钮,你可以使用 TDBGridButtonColumn 组件并设置其 ButtonStyle 属性为 bsGlyph。 以下是一个简单的示例: 1. 在 Delphi 7 的窗体设计器,将一个 TDBGrid 组件放置在你的窗体上。 2. 在窗体上放置一个 TDataSource 组件,并将其 DataSet 属性设置为你要在 DBGrid 显示的数据集3. 打开 DBGridColumns 属性编辑器。点击右侧的“添加”按钮,选择 "TColumn" 类型。 4. 在 "TColumn Editor" 对话框,选择 "TDBGridButtonColumn" 类型。 5. 在 "TDBGridButtonColumn Editor" 对话框,设置 ButtonStyle 属性为 bsGlyph。 6. 在 "TDBGridButtonColumn Editor" 对话框,为 Glyph 属性选择一个合适的图标,用于表示按钮。 7. 在 DBGrid 的 OnDrawColumnCell 事件编写代码来绘制按钮。 ```delphi procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var ButtonRect: TRect; ButtonWidth: Integer; begin if (Column is TDBGridButtonColumn) and (gdFocused in State) then begin ButtonWidth := 18; // 按钮的宽度 ButtonRect.Left := Rect.Right - ButtonWidth - 2; ButtonRect.Right := Rect.Right - 2; ButtonRect.Top := Rect.Top + 2; ButtonRect.Bottom := Rect.Bottom - 2; DBGrid1.Canvas.Pen.Color := clBtnFace; DBGrid1.Canvas.Brush.Color := clBtnFace; DBGrid1.Canvas.Rectangle(ButtonRect); // 在按钮上绘制图标 ImageList1.Draw(DBGrid1.Canvas, ButtonRect.Left + 2, ButtonRect.Top + 2, 0); end; end; ``` 请确保你已经将一个 TImageList 组件放置在窗体上,并将其 Images 属性设置为包含所需图标的图像列表。 现在,每行数据将在最后一列显示一个带有图标的按钮。你可以根据需要自定义按钮的样式、位置和绘制方式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值