找回密码
 立即注册

QQ登录

只需一步,快速开始

jerryannie
中级会员   /  发表于:2012-3-1 18:43  /   查看:5646  /  回复:4
Cell焦点离开时,如何做format处理

比如:自己写了CustomCell继承TextBoxCell ,EditType里放CustomTextBoxEditingControl
        输入  1234
       焦点离开后自动变换为   1,234
做个自动添加数字逗号的功能

可以在CustomTextBoxEditingControl的TerminateEditingControl里设置Cell的Value吗?
但一般做法都是调用DirtyStateChanged来实现改变Cell的Value。
所以我写了OnTextChanged方法来触发DirtyStateChanged
但最后没有变成Format后的值
  1. dfdf
  2. Public Class CustomTextBoxEditingControl

  3. Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
  4.     Me.OnDirtyStateChanged(args)
  5. End Sub

  6. Public Property FormattedValue() As Object Implements IEditingControl.FormattedValue
  7. Get
  8.     Return  Format(CInt(Me.Value), "#,###")
  9. End Get
  10. Set(ByVal value As Object)
  11. .......................................
  12. End Set

  13. End Class
复制代码

4 个回复

倒序浏览
robert
金牌服务用户   /  发表于:2012-3-2 09:25:00
沙发
我觉得不需要自定义Cell就可以实现。请尝试以下代码看是否满足需求。
  1.         Dim template1 As Template = New Template1()
  2.         Dim cell = template1.Row.Cells("textBoxCell1")
  3.         cell.Style.Format = "#,###"
  4.         cell.ValueType = GetType(Integer)
  5.         GcMultiRow1.Template = template1
复制代码
回复 使用道具 举报
jerryannie
中级会员   /  发表于:2012-3-2 10:59:00
板凳
恩,这样可以实现

但如果Format的式样是比较特殊的
有没有办法直接设定Cell的DisplayText的值呢?
回复 使用道具 举报
robert
金牌服务用户   /  发表于:2012-3-2 14:15:00
地板
使用CellFormatting和CellParsing事件可以定制任何Format的逻辑。
我写了一个例子,让Cell在编辑的时候自动在数字后边加个“元”字。你可以参考这段代码定制你的Format逻辑。
  1. Private Sub GcMultiRow1_CellFormatting(sender As Object, e As GrapeCity.Win.MultiRow.CellFormattingEventArgs) Handles GcMultiRow1.CellFormatting
  2.     If e.Value IsNot Nothing Then
  3.         e.Value = e.Value.ToString() + "元"
  4.         e.FormattingApplied = True
  5.     End If
  6. End Sub
  7. Private Sub GcMultiRow1_CellParsing(sender As Object, e As GrapeCity.Win.MultiRow.CellParsingEventArgs) Handles GcMultiRow1.CellParsing
  8.     If e.Value IsNot Nothing Then
  9.         Dim text = e.Value.ToString()
  10.         If text.EndsWith("元") Then
  11.             text = text.Substring(0, text.Length - 1)
  12.         End If
  13.         Dim intValue As Int32
  14.         Int32.TryParse(text, intValue)
  15.         e.Value = intValue
  16.         e.ParsingApplied = True
  17.     End If
  18. End Sub
复制代码
回复 使用道具 举报
jerryannie
中级会员   /  发表于:2012-3-2 16:03:00
5#
ok 我去试试 谢了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部