代码之家  ›  专栏  ›  技术社区  ›  Missy

需要有关复选框的WinForms数据绑定帮助

  •  0
  • Missy  · 技术社区  · 6 年前

    我的复选框在选中时不会导致绑定源发生更改。

    我有一个绑定到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();
    

    这不漂亮,也不是最好的方法,但我必须完成这项工作,我不能搞清楚语法。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Missy    6 年前

    这是一部史诗般的丑陋之作,如果你能用上它的话:

    问题是代码生成器没有生成新的列,这是确定下一步要做什么的关键。