I ‘ve run into the following situation:
try
{
Validate();
myBindingSource.MoveNext();
}
catch
{
if (MessageBox.Show("Do you want to keep editing the record?", "Error",
MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
{
myBindingSource.CancelEdit();
}
}
where myBindingSource.Datasource is a DataTable and the databound textbox updates on validation.
I change the databound textbox of the current record to an invalid state (e.g. duplicate primary key). and when I call the code snippet above naturally an exception is thrown.
In the catch block the value of the field of the row of the datable has reverted to its original value but the textbox value remains the same (I want the same textbox value).
If I call the same snippet again no exception is thrown (DataTable has a correct value).
My question is how do I make textbox to send its data again to the DataTable?
P.S. if after the first calling of the code snippet change the value of textbox the DataSet receives the changes.
My final solution is the following (Though it writes back all the databound controls to the datasource. At least it keeps the datasource and the controls in synch):