none
How to clear control's text inside a groupbox in .net? RRS feed

  • Question

  • I created a bunch of controls(textbox) inside the groupbox. My question is how can I clear all values, meaning  text values inside the groupbox if I click on a button? what method can I use to clear
    all the text values at one time shot? Thanks!

    Mitoy
    Tuesday, July 8, 2008 12:58 AM

Answers

  •     private void button1_Click(object sender, EventArgs e) {
          foreach (Control ctl in groupBox1.Controls)
            if (ctl is TextBox) (ctl as TextBox).Text = "";
        }


    Hans Passant.
    • Marked as answer by Ram - 323 Thursday, July 10, 2008 10:45 PM
    • Marked as answer by Ram - 323 Thursday, July 10, 2008 10:45 PM
    Tuesday, July 8, 2008 3:23 AM
    Moderator

All replies

  •     private void button1_Click(object sender, EventArgs e) {
          foreach (Control ctl in groupBox1.Controls)
            if (ctl is TextBox) (ctl as TextBox).Text = "";
        }


    Hans Passant.
    • Marked as answer by Ram - 323 Thursday, July 10, 2008 10:45 PM
    • Marked as answer by Ram - 323 Thursday, July 10, 2008 10:45 PM
    Tuesday, July 8, 2008 3:23 AM
    Moderator
  • ok! Thanks nobugz! It worked!!
    Mitoy
    Thursday, July 10, 2008 10:45 PM