The problem is that clicking on a button in a ToolStrip control or a MenuStrip control MenuStrip not cause the Validating / Validate events to be raised by the currently selected control. This is by design. Interaction with menus and toolbars does not cause the currently selected control to lose focus, which means that validation never works.
If you think about it carefully, it even makes sense. Imagine that your validation logic required that each cell contain a value (i.e., it did not allow the cells to remain empty or empty). If a verification event was triggered every time a user tried to select an item from a menu or toolbar, they couldn’t even “insert” anything into a cell!
You will have to add a bunch of ugly, extra logic to your form if you insist on overriding this behavior and you run the risk of seriously annoying your user. Suffice it to say that I do not recommend it.
The best solution is to extract your validation logic into a separate method and manually call it at the beginning of the event handler method for each menu item / toolbar that you want to trigger. Alternatively, you can raise the LostFocus event for your DataGridView control at the beginning of your Save button event handler control using the InvokeLostFocus method. Something like:
InvokeLostFocus(myDataGridView, EventArgs.Empty)
Cody gray
source share