Need unique text in textboxes
-
I have a form with 26 textboxes on it. I need each textbox to have text that is unique from any other textbox on the form. What is an easy way to do this? Thanks
-
Well the simplest way I can think of off the top of my head is to put the text boxes in a List and use nested loops like:
public bool ValidateTextBoxen() { List<TextBox> textBoxen = new List<TextBox>(); textBoxen.Add(TextBox1); textBoxen.Add(TextBox2); ... textBoxen.Add(TextBoxN); for(int i = 0; i < textBoxen.Count; i++) { for(int k = 0; k < textBoxen.Count; k++) { if (textBoxen[i].Text == textBoxen[k].Text && i != k ) return false; } } return true }
-- modified at 15:37 Tuesday 25th July, 2006 -
I have a form with 26 textboxes on it. I need each textbox to have text that is unique from any other textbox on the form. What is an easy way to do this? Thanks
Dictionary stringProbe = new Dictionary (); stringProbe[textBox1.Text] = null; ... stringProbe[textBox25.Text] = null; if (stringProbe.ContainsKey(mustBeUniqueTextBox.Text)) { // Text is not unique }else { //Text is unique }