in my windows form application there are multiple textBoxes . How can I delete content of all of theme? I don't want to delete content of textbox one by one with
textBox1.text=string.emty.tostring();
in my windows form application there are multiple textBoxes . How can I delete content of all of theme? I don't want to delete content of textbox one by one with
textBox1.text=string.emty.tostring();
foreach (Textbox myTB in this.Controls)
{
if (myTB != null)
myTB.Text = String.Empty;
}
You don't have to toString() on Empty.
If all these TextBoxes belong to the same container and no other TextBoxes are placed in this container, then you can just enumerate container's children
foreach (var tb in container.Controls.OfType<TextBox>())
{
tb.Text = string.Empty; // or tb.Text = null;
}
If you have multiple textboxes and for some reason you cannot group them in one container you shoud recursively search for all available textboxes and then filter the resulting collection.
You can use Tag
roperty for this.