Leave not being triggered on buttonclick (cursor is not moved)

mfish02

New member
Joined
Oct 5, 2010
Messages
3
Programming Experience
1-3
I am having a problem where I am on a text box and try to click a button that will bring up some reports. Since my cursor is still on the text box it doesn't go through the "Leave" and so what I entered into the text box is not saved (this happens in "Leave"). I have read previously not to use "Lost Focus" because it causes problems when you leave the form it triggers the "Lost Focus" on on the fields and just in general to use "Leave" rather than "Lost Focus". Is there a way to force my way through the "Leave"? I also don't know which field my cursor could be on (there are probably 20 text box or combo box fields on this form.

Any help would be greatly appriciated..this is causing big problems.
 
If you click a Button control then it should receive focus, which means the TextBox or whatever should lose focus, which means that the Leave event should be raised. That suggests that you are not clicking an actual Button control. Is it maybe a button on a ToolStrip you're clicking? They do not receive focus when clicked so that would explain your issue.

In that case, one option would be to handle the Validated event of your other controls instead of Leave. You can then call Validate on the form when the tool bar button is clicked. This may not be an option in all circumstances.
 
I was clicking on a button in a ToolStrip. I didn't realize there was a difference to be honest. I tried what you suggested and it seems to be working for my situation. Thank you so much for your help.
 
Back
Top