checking textboxes
-
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
-
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
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;
}
-
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
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);