This is a winform C# problem.
I have an data object, say, Person. It has a property called Age and if Age is set to a negative value an exception will be thrown from its property setter.
On the form, the Age property is bound to a textbox using:
var binding = tbAge.DataBindings.Add("Text", person, "Age", true, DataSourceUpdateMode.OnValidation);
In order to discover the error, I create an BindingComplete event listener and test the BindingCompleteState against BindingCompleteState.Success and show necessary error message to the user.
That is all the background. Now, if I set a negative value on the textbox and DIRECTLY click the X button on the right top of the form to close it, the expected error message shows but the form is not closed.
I want the form to be closed and don't care if the error message is shown or not in this case. The validation part is preferred not to be altered. I don't want to hide the X button and put a close button on the form manually. Is there any right way to achieve my purpose? Thank you very much for any help.