我有2個使用相同BindingSource的文本框。當我更新一個文本框並失去焦點時,另一個文本框不會將其屬性更新爲新值。當我更改2個綁定文本框中的一個時,相同的DataBinding不更新
任何幫助將不勝感激。
using System.Data;
using System.Windows.Forms;
using System.ComponentModel;
namespace TextBoxes
{
public partial class Form1 : Form
{
BindingSource bs1 = new BindingSource();
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Rows.Add("Donald Trump");
dt.Rows.Add("Sergei Rachmaninoff");
dt.Rows.Add("Bill Gates");
bs1.DataSource = dt;
bs1.RaiseListChangedEvents = true;
bs1.CurrencyManager.Position = 1;
textBox1.DataBindings.Add("Text", bs1, "Name");
textBox2.DataBindings.Add("Text", bs1, "Name");
}
}
}
感謝NDJ。我想用對話框編輯一個datagridview行。這是我的老闆想要的。 – Scott 2013-02-22 14:26:07
您提供的解決方案對此問題最有意義。非常感謝! – Scott 2013-02-22 14:26:47
不客氣!不能與老闆想要的東西爭論:) – NDJ 2013-02-22 14:27:21