【问题标题】:C# WinForms Data Binding on Check Box Help Needed需要 C# WinForms 数据绑定复选框帮助
【发布时间】: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


    【解决方案1】:

    这是史诗般的和丑陋的,所以如果你可以使用它,那就去吧:

    数据库已更改,我已删除数据集子文件并运行自定义工具,但这还不够。所以我删除了数据集,在数据集设计器中编辑了查询,重新生成了 Insert/Update/etc 命令,再次删除了数据集并运行了自定义工具。那行得通。

    问题在于代码生成器没有生成新列,这是弄清楚接下来要做什么的关键。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 2011-02-09
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多