BindingSource、EndEdit 和ErrorProvider 在未更改的字段上引发事件
public class Person
{
private string firstName;
public string FirstName
{
get { return firstName; }
set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException("FirstName cannot be null.");
firstName = value;
}
}
private string lastName;
public string LastName
{
get { return lastName; }
set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException("LastName cannot be null.");
lastName = value;
}
}
public int Age { get; set; }
}
人员字段(文本框)和errorProvider 绑定到 personBindingSource。
有没有办法引发脏事件,以便 errorProvider 能够捕获并显示用户是否未输入名字。目前,只有当您在字段中输入一些字符,然后删除它们时,它才有效,错误提供程序将显示。
即使我打电话,
personBindingSource.EndEdit();
如果我从未在firstName文本框中输入,它也永远不会触发,有什么解决方法吗?
问候
_埃里克
public class Person
{
private string firstName;
public string FirstName
{
get { return firstName; }
set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException("FirstName cannot be null.");
firstName = value;
}
}
private string lastName;
public string LastName
{
get { return lastName; }
set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException("LastName cannot be null.");
lastName = value;
}
}
public int Age { get; set; }
}
The Person fields(textboxes) & errorProvider are bound to personBindingSource.
Is there a way to raise a dirty event so the errorProvider will catch and show if the user did not enter a FirstName. Currently it only works if you tab into the field type some characters, then delete them the error provider will display.
Even though I call
personBindingSource.EndEdit();
if I never typed in the firstName textbox, it will never fire, any workarounds?
Regards
_Eric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在构造函数中或在绑定对象之前的任何其他位置设置
FirstName = ""
。该错误将立即可见。
set
FirstName = ""
, either in the constructor or anywhere else before the object is bound.The error will be visible immediately.