I have a form with a text box on it. I create a BindingSource object, connect my DomainObject to it, then bind the BindingSource to a TextBox. The code looks similar to this:
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; }
}
The code works fine. However, I'd like to know the reason the TextChanged event fires: is it because it is being set by the BindingSource or is it because the user entered something (or pasted it). How do I get that information?
I've tried having a flag that's set when bindings are created, but at the time of the binding, the textbox is on a tab control that's not visible. The event actually fires when I switch to the tab with the textbox in question.