环境:的Visual Studio 2010,.NET 4.0,WinForms的绑定Checkbox.Checked财产财产上的DataSet
我有一个实现INotifyPropertyChanged的一个DataSet,并创造了在DataSet中的布尔属性。我试图绑定一个CheckBox.Checked属性到bool属性。当我尝试在设计器中完成它时,我会看到数据集中的数据集和表格,但不是属性。我试图手动执行该操作,但收到该属性未找到的错误。唯一不同的是,我看到我正在做的是表单上的属性是被实例化的数据集的超类,但我甚至都没有看到这会如何影响任何东西。代码片段如下。
派生类定义
public class DerivedDataSetClass: SuperDataSetClass, INotifyPropertyChanged
{
private bool _mainFile = false;
public bool MainFile
{
get { return this._mainFile; }
set {
this._mainFile = value;
this.NotifyPropertyChanged("MainFile");
}
}
}
属性定义
private SuperDataSetClass _dataSet;
public DerivedDataSetClass DataSet
{
get { return (DerivedDataSetClass)_dataSet;
}
男星
this._DataSet = new DerivedDataSetClass (this);
this.mainFileBindingSource = new BindingSource();
this.mainFileBindingSource.DataSource = typeof(DerivedDataSetClass);
this.mainFileBindingSource.DataMember = "MainFile";
var binding = new Binding("Checked", this.mainFileBindingSource, "MainFile");
this.chkMainFile.DataBindings.Add(binding);
的思考?
不幸的是,这并没有帮助。当表单尝试显示时,我得到一个invalidargument异常,该属性MainFile无法绑定到System.Forms的CheckBindings方法中。 – 2011-05-18 04:53:05
@ wraith808:是的,我转载了你的问题。它来自DataSet'绑定完成的事实 - 检查我的编辑。 – 2011-05-18 10:52:26
感谢您的信息!我试图绕过使用CheckBox点击方法,但考虑到开销和事实,这是一个现有的应用程序,我想这是更清洁。但我很高兴知道原因,解决方法,并且我对所看到的并不疯狂。 ;) – 2011-05-18 18:05:23