In my winform I placed a button which i want to function as a reset button. By pressing it, the texts of all the textboxes on my winform should become empty or in other words textBox.text = ""; I am using the foreach statement but it wasnt working, so I added a try catch to see if there is any Exception error.. Neither does the statement in try body execute nor in the catch body.. Can anyone tell me what am I doing wrong? Thanks in advance.
Btw, my winform has 12 textboxes. 4 each in 3 different groupboxes.
private void button2_Click(object sender, EventArgs e)
{
try
{
foreach (TextBox a in Controls.OfType<TextBox>())
{
a.Text = "";
}
}
catch { MessageBox.Show("Error! Foreach failed"); }
}