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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:24:32+00:00 2026-05-13T18:24:32+00:00

I am looking for a better way to verify that no field is left

  • 0

I am looking for a better way to verify that no field is left blank in a form, currently this is my implementation, if you have a better one it will be welcomed, note tha I am using KryptonControls.

private bool verify(Control c)
{
    switch (c.GetType().Name)
    {
        case "KryptonTextBox":
            {
                if (((KryptonTextBox)c).Text == "")
                {
                    ((KryptonTextBox)c).StateCommon.Border.Color1 = Color.Red;
                    ((KryptonTextBox)c).GotFocus += new EventHandler(ControlGotFocus);
                    return false;
                }
            }
            break;
        case "KryptonComboBox":
            {
                if (((KryptonComboBox)c).SelectedIndex < 0)
                {
                    ((KryptonComboBox)c).StateCommon.ComboBox.Border.Color1 = Color.Red;
                    ((KryptonComboBox)c).GotFocus += new EventHandler(ControlGotFocus);
                    return false;
                }
            }
            break;
        case "KryptonDataGridView":
            {
                if (((KryptonDataGridView)c).Rows.Count <= 0)
                {
                    ((KryptonDataGridView)c).StateCommon.HeaderColumn.Border.Color1 = Color.Red;
                    ((KryptonDataGridView)c).GotFocus += new EventHandler(ControlGotFocus);
                    return false;
                }
            }
            break;
        default:    
            break;
    }

    if (c.Controls.Count > 0)
    {
        foreach (Control cc in c.Controls)
        {
            if (!verify(cc))
            {
                return false;
            }
        }
    }
    return true;
}

so when the user sets focus to a control that has to be verified this code runs:

void ControlGotFocus(object sender, EventArgs e)
{
    switch (sender.GetType().Name)
    {
        case "KryptonTextBox":
            {
                ((KryptonTextBox)sender).StateCommon.Border.Color1 = Color.Gray;
            }
            break;
        case "KryptonComboBox":
            {
                ((KryptonComboBox)sender).StateCommon.ComboBox.Border.Color1 = Color.Gray;
            }
            break;
        case "KryptonDataGridView":
            {
                ((KryptonDataGridView)sender).StateCommon.HeaderColumn.Border.Color1 = Color.Black;
            }
            break;
        default:
            break;
    }
}
  • 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-13T18:24:32+00:00Added an answer on May 13, 2026 at 6:24 pm

    You may optimize code something like this:

    switch (c.GetType().Name)  {  case "KryptonTextBox": }
    

    to:

    TextBox tb = c as TextBox;
    if (tb != null)
        return string.IsNullOrEmpty(tb.Text);
    
    ComboBox cb = c as ComboBox;
    if (cb != null)
       return cb.SelectedIndex < 0;
    
    etc.
    

    But I suggest to use validators for these puproses.

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

Sidebar

Related Questions

I'm looking for a better way to this. I have a chunk of code
I'm looking for a better way (or a note that this is the best
I am looking for a better way to do this, if possible. I have
I have been looking for a better way to handle this issue maybe its
Is there any better way to make this query work? I'm looking for a
This is a segue to my previous question: Looking for a better way to
I'm looking for a better way to use RadioButtons in a form contained inside
I've been looking for a better way to deal with site-specific settings (in this
I'm looking for the better way (aka architecture) to have different kind of DBs
I'm looking for a better way to do this: id key, value; NSMutableDictionary dict;

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.