Instead of changing my 15 textboxes manually, I would like to do it automatically, maybe doing a foreach loop? I don't know what do you call it but this kind of method is usually done when clearing textboxes and controls that is instead of putting a .clear() to all textbox, a method or a loop will be made and all of them would be cleared. How to do this? Sorry if this is somewhat confusing, for I am still a newbie.
AngelicOne
4
Posting Whiz
Recommended Answers
Jump to Post1. You can create an array of all wanted textBoxes:
private void button1_Click(object sender, EventArgs e) { TextBox[] tb = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5 }; for (int i = 0; i < tb.Length; i++) tb[i].Text = String.Empty; }
Jump to Post2. To loop through all controls, and if textBox is found, do something:
private void button2_Click(object sender, EventArgs e) { foreach (Control c in Controls) { if (c is TextBox) c.Text = String.Empty; } }
All 5 Replies
Mitja Bonca
557
Nearly a Posting Maven
Mitja Bonca
557
Nearly a Posting Maven
AngelicOne
4
Posting Whiz
Mitja Bonca
557
Nearly a Posting Maven
AngelicOne
commented:
tnx 4 help
+1
AngelicOne
4
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.