【发布时间】:2010-11-04 18:30:34
【问题描述】:
我有一个带有文本框的表单。我创建了一个 BindingSource 对象,将我的 DomainObject 连接到它,然后将 BindingSource 绑定到一个 TextBox。代码如下所示:
private BindingSource bndSource = new BindingSource();
private void Form1_Load(object sender, EventArgs e) {
bndProposal.DataSource = new DomainObject() { ClientCode = "123", EdiCode = "456" };
txtAgencyClientCode.DataBindings.Add("Text", bndProposal, "ClientCode",
false, DataSourceUpdateMode.OnPropertyChanged, null);
}
private void txtAgencyClientCode_TextChanged(object sender, EventArgs e)
{
Debug.WriteLine("txtAgencyClientCode_TextChanged");
}
public class DomainObject
{
public string ClientCode { get; set; }
public string EdiCode { get; set; }
}
代码运行良好。但是,我想知道 TextChanged 事件触发的原因:是因为它是由 BindingSource 设置的,还是因为用户输入了某些内容(或粘贴了它)。我如何获得这些信息?
我尝试在创建绑定时设置一个标志,但在绑定时,文本框位于不可见的选项卡控件上。当我切换到带有相关文本框的选项卡时,该事件实际上会触发。
【问题讨论】:
标签: c# winforms data-binding