Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear the text in multiple TextBox's at once

Tags:

c#

wpf

I have a WPF application with a Grid where there are multiple TextBoxs. How I can make every TextBox.Text = null; with a button click?

like image 708
Irakli Lekishvili Avatar asked Jan 20 '23 04:01

Irakli Lekishvili


1 Answers

Give this a try:

   private void button1_Click(object sender, RoutedEventArgs e)
    {
        foreach (UIElement control in myGrid.Children)
        {
            if (control.GetType() == typeof(TextBox))
            {
                TextBox txtBox = (TextBox)control;
                txtBox.Text = null;
            }
        }
    }
like image 187
Tom Studee Avatar answered Jan 27 '23 20:01

Tom Studee