Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. checking textboxes

checking textboxes

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toink toink
    wrote on last edited by
    #1

    i have 6 textboxes in my form how will i check if these textboxes doesn't have same inputted values? i have my own solution but seems to me that my could is quite long. please help thanks

    L A 2 Replies Last reply
    0
    • T toink toink

      i have 6 textboxes in my form how will i check if these textboxes doesn't have same inputted values? i have my own solution but seems to me that my could is quite long. please help thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      private bool CheckTextBoxes()
      {
      foreach(Control control in this.Controls)
      {
      TextBox textBox = control as TextBox;
      if(textBox != null)
      {
      foreach(Control otherControl in this.Controls)
      {
      TextBox otherTextBox = otherControl as TextBox;
      if(otherTextBox != null)
      {
      if(!otherTextBox.Equals(textBox))
      {
      if(otherTextBox.Text == textBox.Text)
      {
      return false;
      }
      }
      }
      }
      }
      }

      return true;
      

      }

      1 Reply Last reply
      0
      • T toink toink

        i have 6 textboxes in my form how will i check if these textboxes doesn't have same inputted values? i have my own solution but seems to me that my could is quite long. please help thanks

        A Offline
        A Offline
        Andrew Lygin
        wrote on last edited by
        #3

        Hi, I'd do this:

        private bool CheckTextBoxes(params TextBox[] textboxes)
        {
        bool result = true;
        if (textboxes.Length > 0)
        {
        string standardText = textboxes[0].Text;
        for(int i = 1; i < textboxes.Length; i++)
        {
        if (textboxes[i].Text != standardText)
        {
        result = false;
        break;
        }
        }
        }
        return result;
        }

        Function usage:

        bool equality = CheckTextBoxes(textbox1, textbox2, textbox3, textbox4, textbox5, textbox6);

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups