簡體   English   中英

需要復選框上的C#WinForms數據綁定幫助

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

我的復選框在選中時不會導致綁定源發生更改。

我有一個綁定到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並未更改以反映出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();

它不是很漂亮,也不是最好的方法,但是我必須做到這一點,我無法弄清楚語法。

任何幫助將不勝感激。

這是史詩般的丑陋,因此如果可以使用它,請轉到這里:

數據庫發生了變化,我刪除了數據集子文件並運行自定義工具,但這還不夠。 因此,我刪除了數據集,在數據集設計器中編輯了查詢,重新生成了Insert / Update / etc命令,再次刪除了數據集並運行了自定義工具。 那行得通。

問題在於,新列不是由代碼生成器生成的,而這是弄清楚下一步的關鍵。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM