Thanks,
That helped. It was a little more difficult to understand than I hoped, but
my program works now the way I want it to.
If you're interested:
I have 2 textboxes. Moving focus from textbox 1 to textbox 2 or from textbox
2 to textbox 1 should not fire a validating event. But moving out of textbox
1 or textbox 2 to another control should fire the validating event.
This is the code that works for me:
private void textBox1_Enter(object sender, System.EventArgs e)
{
textBox1.CausesValidation = true;
textBox2.CausesValidation = false;
}
private void textBox1_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("Validating text 1");
TextBox2.CausesValidation = true;
}
private void textBox2_Enter(object sender, System.EventArgs e)
{
textBox2.CausesValidation = true;
textBox1.CausesValidation = false;
}
private void textBox2_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("Validating text 2");
textBox1.CausesValidation = true;
}
"Bruce Wood" <br*******@canada.com> schreef in bericht
news:11**********************@f14g2000cwb.googlegr oups.com...
You want to set CausesValidation on that other, specific control to
false. This will allow that control to gain focus without firing the
Validating event on the text box that the user is leaving. Sort of.
You can read about all the gory details of CausesValidation and
validating in this thread:
http://groups-beta.google.com/group/...87446046433a3b
(watch for line wrap on the URL)
The bottom line is that CausesValidation will (with a few caveats)
solve your problem by preventing your Validating event handler from
being called (sort of... like I said, read the other link), so you
don't have to test for which control has focus in your Validating event
handler.