I have a form with multiple textboxes on and a datatable, the datatable is bound to the textboxes and I am handling the RowChanged event of the datatable.
However the RowChanged event is only called twice when the form is loaded (there are more than two textboxes), the data from the datatable loads fine into the textboxes but when I change the text in the textboxes no event is triggered. Yet displaying the data directly from the datatable shows the data has been updated.
Code:
private Clients.DataSetClients.ClientsDataTable dtClients = new DataSetClients.ClientsDataTable();
private Clients.DataSetClientsTableAdapters.ClientsTableAdapter taClients = new DataSetClientsTableAdapters.ClientsTableAdapter();
private void ClientsEdit_Load(object sender, EventArgs e)
{
dtClients.RowChanged += new DataRowChangeEventHandler(dtClients_RowChanged);
taClients.FillByID(dtClients, ClientID);
textForename.DataBindings.Add("Text", dtClients, "Forename", true, DataSourceUpdateMode.OnPropertyChanged);
//.......
// etc
//.......
textEmail.DataBindings.Add("Text", dtClients, "Email", true, DataSourceUpdateMode.OnPropertyChanged);
}
void dtClients_RowChanged(object sender, DataRowChangeEventArgs e)
{
MessageBox.Show("dtClients_RowChanged");
}
private void simpleButton1_Click(object sender, EventArgs e)
{
MessageBox.Show(dtClients.Rows[0]["Email"].ToString());
}
You can try wiring up the
BindingCompleteevent of the binding instead of the RowChanged event on the DataTable (which is more for adding rows and row position changes, etc).That MessageBox will pop up every time the user changes the text in the TextBox, so it would be firing on every key stroke. To avoid that, change your binding mode to
OnValidation: