matthew king

matthew king

  • NA
  • 52
  • 0

Textbox Validation

Sep 1 2009 2:12 PM
Sir/Ma'am, I'm trying to figure out a method to validate user data in multiple textboxes. I have a textbox where the user enters text and then clicks a button. When the button is clicked the program searches a .txt file and populates three other textboxes based on the user input. For example: I have a text file that has the following information: Hardware, Mr. Kerry, 555-2112, 425 Software, Mrs. Collins, 555-1117, 101 Telephone, Mr. Berry, 555-5874, 101 Purchase, Mr. Timberland, 555-4442, 101 So, if the user enters Hardware into Textbox1, Textboxes 3 - 4 are populated with the corrosponding data (e.g. Texbox2 = Mr. Kerry, Textbox3 = 555-2112, and Textbox4 = 425). Now, I'm trying to figure out a way to return a messagebox if no data is found, or if the user clicked the button without entering any data into Textbox1. { string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(@"c:\poc.txt"); while ((line = file.ReadLine()) != null) { Console.WriteLine(line); string[] lineStrings = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (lineStrings.Length > 4) { if (lineStrings[0] == textBox1.Text) { textBox2.Text = lineStrings[2]; textBox3.Text = lineStrings[3]; textBox4.Text = lineStrings[4]; // Suspend the screen.Console.ReadLine();} Console.ReadLine();

Answers (1)