devexpress - 为什么会抛出无效值?

标签 devexpress textedit

我有一个 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/

相关文章:

c# - 如何避免输入空格和特殊字符

eclipse - Eclipse 中所选单词的括号

linux - 输出列格式排序 linux

macos - 如何在 MacOS 中查找东亚字符的默认字体

c# - 为什么 textedit 验证处理程序被调用两次?

c# - 如何在单击时启用禁用的控件

json - 我可以将 json 动态格式化为 devexpress 图表所需的格式吗

c# - 双击后 Devexpress GridContol 检查值变化

unix - 我需要删除文本文件中每一行从位置 X 到位置 Y 的字符串

winforms - 如何更改 Devexpress WinForm 应用程序的默认主题