I have a large group of text boxes, each with the same KeyPress
(numeric values only) event and Validating event (trimmedInput).
The trouble I am having is that if the user clicks into one of the text boxes that has the validating event, the user can do nothing else, including close the form without entering the text in the appropriate format. If the user TabIndex
following the correct entry, the user gets stuck again in the next box and can't exit, or perform any other functions in the form without first entering the correct format and then clicking out of the textbox. Here is my code snipit for the validating event:
double value;
var trimmedInput = tbGRS1A.Text.Trim();
if (trimmedInput.Length != 5 || trimmedInput.IndexOf('.') != 3
|| !double.TryParse(trimmedInput, out value))
{
e.Cancel = true;
MessageBox.Show("Temperature Format: 123.4");
tbGRS1A.Text = "";
}
Ideally I would like to find a way that if the user encounters the error, and they click ok, that the text box clears and the user is free to make changes outside the focus of the textbox or even close the form. I have tried a few different things and nothing seems to work.
Also tried a FormClosing
event with no success...