在相关但非互斥的复选框上使用 IDataErrorInfo
我的表单上有一系列复选框。必须检查一个或多个,如果没有,我想在它们上显示一个错误图标,直到其中之一为止。
我的 IDataErrorInfo 实现如下所示:
public string this[string columnName]
{
get
{
switch (columnName)
{
case "option1":
case "option2":
case "option3":
if (!this.option1 && !this.option2 && !this.option3)
return "Please select one or more of the 3 options";
}
}
}
现在,如果没有选中任何绑定到 options1-3 的复选框,则每个复选框上都会有一个错误图标,这很好,但是当选中其中一个复选框时,只有该复选框将删除其错误图标(而不是所有错误图标)。
当选项 1-3 中的任何一个发生更改时,对选项 1-3 进行表单重新轮询验证的理想方法是什么?
如果它有帮助(尽管我认为它应该与普通的 winforms 控件没有太大不同),我正在使用 DevExpress UI 控件,因此复选框是 CheckBoxEdit 的,ErrorProvider 是 DxErrorProvider 。
编辑:已解决
当一个选项发生更改时,我最终手动通知其他选项的属性已更改。
private bool option1;
public bool Option1
{
get { return this.option1; }
set
{
this.option1 = value;
this.notifyPropertyChanged("Option1");
this.notifyPropertyChanged("Option2");
this.notifyPropertyChanged("Option3");
}
}
// repeat for options2-3
I have a series of checkboxes on a form. One or more must be checked, and if not I want to display an error icon on them until one of them is.
My IDataErrorInfo implementation looks like so:
public string this[string columnName]
{
get
{
switch (columnName)
{
case "option1":
case "option2":
case "option3":
if (!this.option1 && !this.option2 && !this.option3)
return "Please select one or more of the 3 options";
}
}
}
Now, if none of the checkboxes that are bound to options1-3 are checked, each checkbox will have an error icon on them, which is fine, but when one of them IS checked, only that one checkbox will have its error icon removed (as opposed to all of them).
What's the ideal way of having the form re-poll validation for options1-3 when any one of them is changed?
If it helps (though I don't think it should be much different from normal winforms controls), I'm using DevExpress UI controls, so the checkboxes are CheckBoxEdit's and the ErrorProvider is the DxErrorProvider.
EDIT: SOLVED
I ended up manually notifying of property changed for the other options when one was changed.
private bool option1;
public bool Option1
{
get { return this.option1; }
set
{
this.option1 = value;
this.notifyPropertyChanged("Option1");
this.notifyPropertyChanged("Option2");
this.notifyPropertyChanged("Option3");
}
}
// repeat for options2-3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论