I have an application with a textbox that involves other controls, some of which require valid data in the textbox, while others do not. When the textbox value is not valid, I want to disable the controls that require valid data, but still allow the user to activate the other controls. I have been doing this in the Leave Event:
privatevoid TextBox1_Leave(object sender, EventArgs e)
{
pnlGoodStuff.Enabled = IsValidData(TextBox1.Text);
}
The problem is, when the data is not valid and the control gaining focus happens to be one of the ones disabled, focus does not leave the textbox. Users are able to modify the value before attempting to leave again. Unfortunately, at this point the control does not fire another Leave event. Apparently, even though the user has changed the value since the previous Leave event, the control still considers itself as having already been left. Thus, even if the data is now valid, the user has to leave the textbox, re-enter it, and leave it again manually before another Leave event will fire and the volatile controls are enabled.
I could use a different event than Leave, but two things I don't want to do are:
* Check for valid data before the user is finished entering it. (I don't want is the volatile controls flashing on and off as the user types!)
* Use the CancelEventArgs Cancel event. The users need to be able to leave the textbox with invalid data, provided they are moving to a control that doesn't depend on that data.