1
我有一个复选框,谁的选中值绑定到绑定到一个布尔数据表列的绑定源。当我点击我的保存按钮将我的数据表中的更改推送到我的sql服务器时,数据表中的值永远不会改变。绑定复选框不会更新其数据源
设计者代码。
this.cbxKeepWebInfinityChanges = new System.Windows.Forms.CheckBox();
this.preProductionBindingSource = new System.Windows.Forms.BindingSource();
//
// cbxKeepWebInfinityChanges
//
this.cbxKeepWebInfinityChanges.AutoSize = true;
this.cbxKeepWebInfinityChanges.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.preProductionBindingSource, "WEBINFINTY_CHANGES", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
this.cbxKeepWebInfinityChanges.Location = new System.Drawing.Point(6, 98);
this.cbxKeepWebInfinityChanges.Name = "cbxKeepWebInfinityChanges";
this.cbxKeepWebInfinityChanges.Size = new System.Drawing.Size(152, 17);
this.cbxKeepWebInfinityChanges.TabIndex = 30;
this.cbxKeepWebInfinityChanges.Text = "Keep WebInfinity Changes";
this.cbxKeepWebInfinityChanges.UseVisualStyleBackColor = true;
this.cbxKeepWebInfinityChanges.CheckedChanged += new System.EventHandler(this.CauseApplyChangesActivation);
//
// preProductionBindingSource
//
this.preProductionBindingSource.AllowNew = false;
this.preProductionBindingSource.DataMember = "PreProduction";
this.preProductionBindingSource.DataSource = this.salesLogix;
节省代码
//the comments are the debugger values before the call in going from checked when loaded to unchecked when saved.
private void btnApplyChanges_Click(object sender, EventArgs e)
{
(...) // non related saving logic for other controls
preProductionBindingSource.EndEdit(); // checked = false, databinding = true, datatable = true
preProductionTableAdapter.Update(salesLogix.PreProduction); // checked = false, databinding = true, datatable = true
}
同样的事情会从选中到选中时发生。其他项目绑定到相同的数据绑定源(我有两个组合框)正在更新。
编辑 - 添加cbxKeepWebInfinityChanges.DataBindings["Checked"].WriteValue();
之前preProductionBindingSource.EndEdit();
没有改变任何东西。