【问题标题】:binding Textbox to DGV and clearing it?将文本框绑定到 DGV 并清除它?
【发布时间】:2015-03-16 13:23:25
【问题描述】:

我检查了以下链接中的问题: This causes two bindings in the collection to bind to the same property. Parameter name: binding error in c#?

我遵循了给定的答案。错误消失了,但出现了新问题:

有一个 DGV,当我单击它的单元格时,一些文本框会绑定到选定的行。当我点击其他行之后,它会清除 DGV 中的第一行。

代码:

                    this.SupportPersonnelIDtxt.DataBindings.Clear();
                    this.SupportCallingPersontxt.DataBindings.Clear();
                    this.SupportCustomerProductIDtxt.DataBindings.Clear();
                    this.SupportIssuetxt.DataBindings.Clear();
                    this.SupportServicetxt.DataBindings.Clear();
                    this.SupportResulttxt.DataBindings.Clear();
                    this.SupportDescriptiontxt.DataBindings.Clear();
                    this.SupportdatePicker.DataBindings.Clear();

                    this.SupportPersonnelIDtxt.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.supportTblBindingSource, "Operator", true));
                    this.SupportCallingPersontxt.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.supportTblBindingSource, "CallingPerson", true));
                    this.SupportCustomerProductIDtxt.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.supportTblBindingSource, "Product", true));
                    this.SupportIssuetxt.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.supportTblBindingSource, "Issue", true));
                    this.SupportServicetxt.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.supportTblBindingSource, "Service", true));
                    this.SupportResulttxt.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.supportTblBindingSource, "Description", true));
                    this.SupportDescriptiontxt.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.supportTblBindingSource, "Result", true));
                    this.SupportdatePicker.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.supportTblBindingSource, "Date", true));

【问题讨论】:

  • 解释你的问题更多
  • 我不想清除 DGV。我该怎么做?

标签: c# wpf binding


【解决方案1】:

我尝试了一个更好的方法。这就是我用 DGV 中所选行的值填充文本框的方式。

代码:

SupportPersonnelIDtxt.Text = dataGridView7.Rows[e.RowIndex].Cells[0].Value.ToString();

【讨论】:

    猜你喜欢
    • 2017-08-05
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    相关资源
    最近更新 更多