[英]How to limit the amount of characters allowed in a databound WinForms TextBox
I have text boxes that are data bound to a field in a database and am using Entity Framework.我有文本框,这些文本框是数据绑定到数据库中的字段并且正在使用实体框架。 The limit on the field is 10. How can I have the control recognize this limit?该字段的限制是 10。我怎样才能让控件识别这个限制?
Mark up your entitiy metadata with the following Data Annotation:使用以下数据注释标记您的实体元数据:
[StringLength(4, ErrorMessage = "The string value cannot exceed 4 characters. ")]
http://msdn.microsoft.com/en-us/data/gg193959 http://msdn.microsoft.com/en-us/data/gg193959
There is no connection between data annotation / entity framework metadata and winform controls = it will not set MaxLength
for you or add automatic validation.数据注释/实体框架元数据和 winform 控件之间没有联系 = 它不会为您设置MaxLength
或添加自动验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.