【发布时间】:2011-03-08 12:29:23
【问题描述】:
我有一个包含 bindingsource 的 winform,它的数据源是一个类型化的数据集。我在设计器中将两个文本框绑定到同一列。当我更新任一文本框时,DatSet 中的 DataRow 列已正确更新,但表单上的其他文本框值未更新。
我错过了什么?如何让数据绑定更新第二个文本框?
注意:这是一个简化的示例,我需要这样做,因为在实际应用程序中,一个控件可由用户编辑,另一个是用于计算的复合控件的输入。
// Taken from InitializeComponent()
this.productsBindingSource.DataMember = "Products";
this.productsBindingSource.DataSource = this.dataSet1;
this.textBox1.DataBindings.Add(new Binding("Text", this.productsBindingSource, "UnitsInStock", true, DataSourceUpdateMode.OnPropertyChanged));
this.textBox2.DataBindings.Add(new Binding("Text", this.productsBindingSource, "UnitsInStock", true, DataSourceUpdateMode.OnPropertyChanged));
// Taken from Form Load Event
DataSet1TableAdapters.ProductsTableAdapter adapter = new DataSet1TableAdapters.ProductsTableAdapter();
adapter.Fill(dataSet1.Products);
【问题讨论】:
标签: winforms data-binding dataset