Linq、错误提供程序、数据绑定:自定义错误消息
我们正在开发一个 C# Windows 窗体应用程序,使用 LINQ-to-sql、数据绑定和错误提供程序对象。
当您尝试输入不允许的数据(例如在数字字段中输入字母数字字符)时,数据绑定会立即显示自动生成的消息。但生成的消息不是很用户友好(输入字符串格式不正确、值无效、值不是从 pos 0 开始的日期时间等)。
您认为处理这个问题的最佳方法是什么?通过在数据绑定控件上将“FormattingEnabled”设置为 false 来关闭自动验证,这意味着您必须自己处理所有验证?或者也许扩展对象能够覆盖消息,例如扩展/覆盖 TypeConverter?制作执行基本验证的自定义控件(例如创建仅允许整数、货币值等的文本框)?
We're developing a C# Windows Forms application, using LINQ-to-sql, databindding and the Error provider object.
The databinding causes autogenerated messages being displayed as soon as you try to enter data which is'nt allowed (for instance entering alphanumeric characters in a numeric field). But the messages being generated are not very user-friendly (input string not in correct format, value is not valid, value is not a datetime starting at pos 0, etc.).
What do you think is the best way to handle this? Turn off the autovalidation by setting "FormattingEnabled" to false on databinded controls, which means you have to handle all validations by yourself? Or perhaps extend objects to be able to override messages, for instance extend/override TypeConverter? Make custom controls which perform basic validation (like creating a textbox which only allows integers, money values, etc.)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果是我,我会将文本框内容限制为仅允许 int 等...
或者如果文本框的值为 null,则添加 messageBox.Show。
您需要一个如何执行此操作的示例吗?
If it was me I would limit Textbox content to only allow int, etc...
Or add a messageBox.Show if the value is null for the text box.
Do you need an example of how to do this?
我最终所做的是制作自定义输入控件,其中:
What I eventually did is make custom input controls which: