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

  • Home
  • SEARCH
  • 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 451973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:01:35+00:00 2026-05-12T22:01:35+00:00

Is there any way to force control validation in .NET CF? In full .NET

  • 0

Is there any way to force control validation in .NET CF? In full .NET there is the Validate() method, but it is missing from CF.

I’m trying to make a control bind data back to the model when closing the form, but clicking the main menu button doesn’t seem to steal focus from the control and the Validating and Validated events don’t fire.

Do you know of any workarounds for this problem?

  • 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-12T22:01:35+00:00Added an answer on May 12, 2026 at 10:01 pm

    I struggled with very same issue about a year ago. Everything I found on the web was pretty nasty (i.e. iterate over controls and catch every control focus thus firing validate event or some solution that heavily relied on pinvoke or reflection – I don’t exactly remember).

    I ended up creating wrappers that included Validate method for my textboxes etc. and keeping collection of this wrappers. This way, I could iterate over my wrappers and call validate for every control.

    That solution worked fine. First I tried the solution with programmatically catching every control focus but I had lots of problems with it. After wasting some time trying to improve this solution I decided to create these wrappers and this was very good decision.

    UPDATE

    Here how it looked like. Inform I declare list of controls that need to be validated:

    private List<TextBoxWithValidation> textBoxesWithValidation;
    

    In constructor I add controls to the list:

    TextBoxWithValidation emailTextBoxWithValidation = new TextBoxWithValidation(emailTextBox);
    emailTextBoxWithValidation.AddValidationPair(Validator.ValidationType.VALIDATE_NOT_EMPTY, "ValidateNotEmptyEmail");
    emailTextBoxWithValidation.AddValidationPair(Validator.ValidationType.VALIDATE_EMAIL, "ValidateEmailEmail");
    textBoxesWithValidation.Add(emailTextBoxWithValidation);
    

    Then I am able to validate the form:

    private bool ValidateForm()
    {
      foreach (TextBoxWithValidation textBoxWithValidation in textBoxesWithValidation)
      {
        if (!textBoxWithValidation.Validate())
        {
          return false;
        }
      }
      return true;
    }
    

    And textbox with validation looks like this:

    class TextBoxWithValidation
    {
      class ValidationTypeMessagePair
      {
        public Validator.ValidationType ValidationType { get; set; }
        public string ValidationMessage { get; set; }
    
        public ValidationTypeMessagePair(Validator.ValidationType validationType, string validationMessage)
        {
          this.ValidationType = validationType;
          this.ValidationMessage = validationMessage;
        }
      }
    
      private List<ValidationTypeMessagePair> validationPairs;
      private TextBox textBox;
    
      public TextBoxWithValidation(TextBox textBox)
      {
        this.textBox = textBox;
        this.textBox.DataBindings["Text"].DataSourceUpdateMode = DataSourceUpdateMode.Never;            
        validationPairs = new List<ValidationTypeMessagePair>();
      }
    
      public void AddValidationPair(Validator.ValidationType validationType, string validationMessage)
      {
        validationPairs.Add(new ValidationTypeMessagePair(validationType, validationMessage));
      }
    
      public bool Validate()
      {
        foreach (ValidationTypeMessagePair validationPair in validationPairs)
        {
          if (!Validator.Validate(validationPair.ValidationType, textBox, Messages.Localize(validationPair.ValidationMessage))) return false;
        }
        textBox.DataBindings["Text"].WriteValue();
        return true;
      }
    
      public void ClearValidationStatus()
      {
        textBox.BackColor = System.Drawing.SystemColors.Window;
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to force a listview control to treat all clicks as
Is there any way to force an update of software using RunOnce, without having
Is there any way to force Outlook to display HTML in the desktop alert
Is there any way to force Text-Mate to use a two-space tab instead of
Is there any way to force PHP to blow up (error, whatever) if I
Is there any way to force Visual Studio to copy selected code to the
Is there any way to force a Route to be executed, only if all
Is there any way to force a browser to refresh or empty it's cache,
Is there any way to force wpf to run the value converter again on
Is there any way to force an alignment of a particular element of a

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.