简体   繁体   中英

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:

        // 
        // 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.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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