Data source updated even if e.Cancel = true in Validating handler
-
Hi everyone, I have a textbox on a form with a Validating event handler attached. The textbox is bound to a data source. The code for the event handler is given below. Basically, the amount entered in the text field should not exceed the amount in the balance field. If this happens, error provider is set and Validating event is cancelled, giving the user the opportunity to correct the amount. On the UI side e'thing is working fine, however I noticed that the data source is updated regardless, even if e.Cancel is set to true. That is a problem because the data source should never be set to an invalid value as it is taken as input for other calculations. I expected that the data source would not be updated if e.Cancel is set to 'true'. Am I missing something? Thanks, Roel private void textBoxCash_Validating(object sender, CancelEventArgs e) { if (Convert.ToDouble(textBoxCash.Text) > this.balance) { errorProvider.SetError(textBoxGenerateCash, "Cash exceeds balance"); e.Cancel = true; } else { errorProvider.SetError(textBoxCash, null); } }