環境:的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