Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3854010
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:33:28+00:00 2026-05-19T17:33:28+00:00

Hi I have a windows form containing a menu bar, tool strip and a

  • 0

Hi I have a windows form containing a menu bar, tool strip and a DataGridView control.
I am using VB.Net.

I have a save button on the tool strip and a save menu item. I need validation to run before save occurs. My problem is that if a cells value is changed and then either of the save buttons is clicked, validation does not run and so the new value is not saved.

I have had a look at the events on the DataGridView such as the ‘leave’ event however none seem to do what I want. I.e. ‘leave’ does not run when either of the save buttons is clicked.

Does anyone know of a way I can run my validation code when one of these buttons is clicked (or any other button).

Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:33:28+00:00Added an answer on May 19, 2026 at 5:33 pm

    The issue is that clicking on either a button on a ToolStrip control or an item on a MenuStrip control does not cause the Validating/Validate events to be raised by the currently selected control. This is by-design. Interacting with menus and toolbars does not cause the currently selected control to lose focus, which means that validation is never triggered.

    If you think about it carefully, this even makes sense. Imagine that your validation logic required each cell to contain a value (i.e., it prevented cells from being left blank or empty). If the validation event was triggered each time that a user tried to select an item from a menu or toolbar, they couldn’t even “Paste” anything into the cell!

    You’ll have to add a bunch of ugly, additional 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 don’t recommend it.

    The better solution is to extract your validation logic into a separate method, and call it manually at the beginning of the event handler method for each menu/toolstrip item that you want to trigger validation. Alternatively, you could raise the LostFocus event for your DataGridView control at the beginning of your Save toolstrip button click event handler using the InvokeLostFocus method. Something like:

    InvokeLostFocus(myDataGridView, EventArgs.Empty)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have .Net 2.0 Windows form containing combobxes. I have written following code to
I have a Windows Form window containing a FlowLayoutPanel, an OK Button, and a
I have this simple piece of code on a windows form containing said DataGridView
I'm using C# and I have windows form and web service... I have a
I have a pretty basic windows form app in .Net. All the code is
I have a simple .NET 2.0 windows form app that runs off of a
I have a radio button on my Windows Form. How can I determine if
I have a base Windows Form with a control. I have declared the control
I have a C# Windows Forms project with a Form containing 2 ListBoxes and
I have created a Windows form using Visual C# - this contains a rich

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.