【发布时间】:2019-02-05 19:17:33
【问题描述】:
我的复选框在选中时不会导致绑定源更改。
我有一个绑定到 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;
在表适配器中定义为 System.Byte。
我正在使用此代码保存:
this.ProcessingBindingSource.EndEdit();
this.ProcessingTableAdapter.Update(rMSDataSet);
myDataSet.AcceptChanges();
除我的复选框外,其他所有字段都会保存。我将绑定源检查回我的表,除了 ProcessingBindingSource -> 当前行 -> rtoverride 没有更改以反映已检查的新值 = 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();
它并不漂亮,也不是最好的方法,但我必须完成它,我无法弄清楚语法。
任何帮助将不胜感激。
【问题讨论】:
标签: c# winforms checkbox data-binding