Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easy way to set all empty string textbox ("") to null value in Csharp winform?

Suppose I don't want to use

if (string.IsNullOrEmpty(textbox1.Text))
{
     textbox1.Text = null;
}

for every textbox controls in form, is there a easier way to do it ?

like image 427
JatSing Avatar asked Jan 18 '26 20:01

JatSing


1 Answers

Simple way is Loop through every control, see the below code

 foreach (Control C in this.Controls)
 {
       if (C is TextBox)
       {
            if (C.Text == "")
            {
                 C.Text = null;
             }
       }
 }
like image 137
Sai Kalyan Kumar Akshinthala Avatar answered Jan 20 '26 12:01

Sai Kalyan Kumar Akshinthala