我有一个 DevExpress TextEdit,它与数据集进行数据绑定(bind)。
该字段是一个可选的百分比(数据类型 double )。
当记录加载并且字段中没有值时,一切都很好。
但是,如果您在字段中输入某些内容 (IE 100),然后想将其删除,我会收到“无效值”错误。
为什么会发生这种情况?如何删除它?
我对此字段没有任何掩码或任何类型的显式验证。
最佳答案
我在 DevExpress 论坛上的 Brendon Muck 的帮助下解决了这个问题。
我的一个 TextEdit 绑定(bind)到 Text 属性而不是 EditValue(所有都应该绑定(bind)到 EditValue)
另外,根据布伦登
Deleting the text out of the TextEdit control doesn't set the field to NULL. You'd have to handle the EditValueChanged event and manually set the value to null when an empty string is detected.
所以,我创建了处理它的方法
Private Sub SetTextEditToNull(ByVal sender As TextEdit)
If String.IsNullOrEmpty(sender.EditValue.ToString.Trim()) And (Not sender.EditValue Is DBNull.Value) Then
sender.EditValue = DBNull.Value
End If
End Sub
在我的事件处理程序中我使用:
SetTextEditToNull(CType(sender, TextEdit))
关于devexpress - 为什么会抛出无效值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2540436/