【发布时间】:2011-05-17 21:19:13
【问题描述】:
环境: Visual Studio 2010、.NET 4.0、WinForms
我有一个实现INotifyPropertyChanged 的DataSet,并在DataSet 上创建了一个bool 属性。我正在尝试将 CheckBox.Checked 属性绑定到该 bool 属性。当我尝试在设计器中执行此操作时,我看到 DataSet 和 DataSet 中的表格,但看不到属性。我尝试手动执行此操作,但收到未找到该属性的错误。我看到我正在做的唯一不同的事情是表单上的属性是正在实例化的DataSet 的超类,但我什至看不出这会如何影响任何事情。下面是一个代码 sn-p。
派生类定义
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);
想法?
【问题讨论】:
标签: c# winforms data-binding