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 8560301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:14:44+00:00 2026-06-11T16:14:44+00:00

Currently I am using a class as follows to check if yhe TextBoxes on

  • 0

Currently I am using a class as follows to check if yhe TextBoxes on the form that I register to it, all have a non-blank text or not and it work fine, But now I want to also add a ComboBox to this validation so that validation should be done when none of the registered textboxes AND Combobxes on the form are blank.
So if I want to add a Combobx to this class, how should it look like? what is the best pracitce to do it?

public class InputValidator
{
    public delegate void ValidationDoneDelegate(bool enable);

    public event ValidationDoneDelegate ValidationDone;

    public void RegisterTextBox(TextBox tb)
    {
        tb.TextChanged += (s, e) => this.Validate(s);
    }

    private void Validate(object sender)
    {
        var t = sender as TextBox;

        if (t == null)
        {
            return;
        }

        var validationDone = ValidationDone;

        if (validationDone != null)
        {
            validationDone(!string.IsNullOrEmpty(t.Text));
        }
    }
}
  • 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-06-11T16:14:45+00:00Added an answer on June 11, 2026 at 4:14 pm

    I have two lists setup which will hold all the TextBox and ComboBox references. When it is time to validate, we will check all of the registered controls and if ANY of them are empty, we will be invalid. I think you will also be able to see how this can easily be extended to support additional control types.

    public class InputValidator
    {
        public delegate void ValidationDoneDelegate(bool enable);
    
        public event ValidationDoneDelegate ValidationDone;
    
        private List<TextBox> textBoxes = new List<TextBox>();
        private List<ComboBox> comboBoxes = new List<ComboBox>(); 
    
        public void RegisterTextBox(TextBox tb)
        {
            tb.TextChanged += (s, e) => this.Validate();
            textBoxes.Add(tb);
        }
    
        public void RegisterComboBox(ComboBox cb)
        {
            cb.SelectedValueChanged += (s, e) => this.Validate();
            comboBoxes.Add(cb);
        }
    
        private void Validate()
        {
            bool isValid = true;
    
            foreach (var tb in textBoxes)
            {
                if (string.IsNullOrEmpty(tb.Text))
                    isValid = false;
            }
    
            if (isValid)
            {
                foreach (var cb in comboBoxes)
                {
                    if (cb.SelectedItem == null)
                        isValid = false;
                }
            }
    
            var validationDone = ValidationDone;
    
            if (validationDone != null)
            {
                validationDone(isValid);
            }
        }
    }
    

    Now I’m not sure exactly what you consider to be invalid input for the ComboBox. So you may need to tweak this line to meet your needs: isValid = cb.SelectedItem != null;. I have assemed that as long as something is selected that the selection is valid.

    EDIT: I had forgotten to switch the last line to validationDone(isValid);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a helper class that I am using to obfuscate a static
I am developing a web form using Visual Web Developer Currently I have class
Currently I have a form that makes use of fields and check boxes. The
I currently have a class file with the following enumeration: using System; namespace Helper
In my programming class we currently have a project that requires us to take
I'm currently using a select as follows (within a form): <% form_for :search, :url
I am currently using a email form, which posts some text once the email
I currently have an input form. There are two entries for each input class
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
I'm reading some XML with PHP and currently using the DOMDocument class to do

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.