我的复选框在选中时不会导致绑定源发生更改。
我有一个绑定到SQL表(定义为TinyInt)的复选框,如下所示:
//
// overrideCheckBox
//
this.overrideCheckBox.CausesValidation = false;
this.overrideCheckBox.DataBindings.Add(new
System.Windows.Forms.Binding("CheckState", this.ProcessingBindingSource, "rtoverride", true));
this.overrideCheckBox.Location = new System.Drawing.Point(354, 378);
this.overrideCheckBox.Name = "overrideCheckBox";
this.overrideCheckBox.Size = new System.Drawing.Size(104, 24);
this.overrideCheckBox.TabIndex = 70;
this.overrideCheckBox.Text = "Override";
this.overrideCheckBox.UseVisualStyleBackColor = true;
this.overrideCheckBox.Visible = false;
它的定义是系统字节在表适配器中。
我用这个代码来保存:
this.ProcessingBindingSource.EndEdit();
this.ProcessingTableAdapter.Update(rMSDataSet);
myDataSet.AcceptChanges();
除了我的复选框,其他字段都保存。我将绑定源代码检查回表中,除了ProcessingBindingSource->current row->rtoverride没有更改以反映checked=1的新值。
有些事情不对劲,我想用这样的方法来破解它:
if (overrideCheckBox.Checked)
{
// in the ProcessingBindingSource at ProcessingBindingSource.Position change the value from 0 to 1
}
this.ProcessingBindingSource.EndEdit();
this.ProcessingTableAdapter.Update(rMSDataSet);
myDataSet.AcceptChanges();
这不漂亮,也不是最好的方法,但我必须完成这项工作,我不能搞清楚语法。