Component EditMask 运用中的Bug分析

来源:互联网 发布:淘宝的详情页在那设置 编辑:程序博客网 时间:2024/06/15 17:12

最近在项目中用到组件的EditMask属性,但应用中觉得有些不尽人意。在网上搜了一些资料,发现在单纯Textbox中应用这个属性是没问题的,但在GridView网格中应用出现问题,没能按照计划完成功能。

Component EditMask 属性如下:

 

Placeholder

Description

#

Digit placeholder permits a numeric character or a plus or minus sign in this position (entry optional).

.

Decimal placeholder. The actual character used is the one specified as the decimal placeholder in your international settings. This character is treated as a literal for masking purposes.

,

Thousands separator. The actual character used is the one specified as the thousands separator in your international settings. This character is treated as a literal for masking purposes.

:

Time separator. The actual character used is the one specified as the time separator in your international settings. This character is treated as a literal for masking purposes.

/

Date separator. The actual character used is the one specified as the date separator in your international settings. This character is treated as a literal for masking purposes.

/

Treat the next character in the mask string as a literal. This allows you to include the #, &, A, … characters in the mask. This character is treated as a literal for masking purposes.

&

Character placeholder (entry required). Any character is permitted.

Convert all the characters that follow to uppercase.

Convert all the characters that follow to lowercase.

~

Turns off the previous < or >.

!

Causes the optional characters that follow in the edit mask to display from right to left, rather than from left to right. So, blanks appear on the left.

^

Turns off the previous ! character. After ^, blanks appear on the right.

A

Alphanumeric character placeholder (entry required). For example: a – z, A – Z, or 0 – 9.

a

Alphanumeric character placeholder (entry optional).

0

Digit placeholder (entry required). For example: 0 – 9.

9

Digit placeholder (entry optional).

C

Character or space placeholder (entry optional). Any character is permitted.

L

Letter placeholder (entry required). For example: a – z or A – Z.

?

Letter placeholder (entry optional).

/n

New line literal. It is applicable when Multiline property is set to True.

"

All characters in a string enclosed in double quotes are considered as literals.

Literal

All other symbols are displayed as literals; that is, as themselves.

 

EditMask最大的作用在于可以控制输入格式,以此代替校验。在GridView中应用此属性,限制网格只能输入Decimal类型,如想要控制为Decimal(8,2),则应该设置为“######.##”.但调试错误结果却为“1     4.05”是可以校验通过的,这就失去了EditMask属性的作用。因为未能自动清空空格,且如输入“102.05”后,再次编辑网格,会出现小数点后两位自动前提的情况,即“10205.”。就是说在Gridview中应用EditMask属性是无法校验Decimal类型参数的。但这一点在普通Textbox中是应用正常的,已得到验证。

 

因此,项目中只能改为输入参数后弹出消息校验,增加了开发工作量。在此记录下个人的开发心得,希望有机会看到Component EditMask 源码,并完善此Bug。