简体   繁体   English

需要复选框上的C#WinForms数据绑定帮助

[英]C# WinForms Data Binding on Check Box Help Needed

My check box is not causing the binding source to change when checked. 我的复选框在选中时不会导致绑定源发生更改。

I have a checkbox that is bound to an SQL table (defined as TinyInt) like so: 我有一个绑定到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;

It's defined as System.Byte in the table adapter. 它在表适配器中定义为System.Byte。

I'm using this code to save: 我正在使用以下代码进行保存:

        this.ProcessingBindingSource.EndEdit();
        this.ProcessingTableAdapter.Update(rMSDataSet);
        myDataSet.AcceptChanges();

Every other field saves except my checkbox. 除我的复选框外,所有其他字段均保存。 I checked my binding source back to my table and everything seems correct except ProcessingBindingSource -> current row -> rtoverride hasn't changed to reflect the new value of checked = 1. 我将绑定源检查回到表中,除ProcessingBindingSource->当前行-> rtoverride并未更改以反映出checked = 1的新值外,其他一切似乎都是正确的。

Something is not right and I'm trying to hack through it with something like this: 某些错误是不正确的,我正在尝试通过类似以下方法来破解它:

      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();

It is not beautiful nor is it the best way to do it but I have to get this done and I can't figure out the syntax. 它不是很漂亮,也不是最好的方法,但是我必须做到这一点,我无法弄清楚语法。

Any help would be greatly appreciated. 任何帮助将不胜感激。

This was epic and ugly so here you go if you can use it: 这是史诗般的丑陋,因此如果可以使用它,请转到这里:

The database changed and I had deleted the data set subfiles and run custom tool but that was not enough. 数据库发生了变化,我删除了数据集子文件并运行自定义工具,但这还不够。 So I deleted the data set, edited the query in the data set designer, regenerated the Insert/Update/etc commands, deleted the data set again and ran the custom tool. 因此,我删除了数据集,在数据集设计器中编辑了查询,重新生成了Insert / Update / etc命令,再次删除了数据集并运行了自定义工具。 That worked. 那行得通。

The problem was that the new columns hadn't been generate by the code generator and that was the key to figuring out what was next. 问题在于,新列不是由代码生成器生成的,而这是弄清楚下一步的关键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM