It is very boring process to set null in all textbox field if you have a lot no of field ..
so you can apply following codes in your project ..
foreach (Control txt in this.Controls)
{
if (txt.GetType() == typeof(TextBox))
if (!string.IsNullOrEmpty(txt.Text))
txt.Text = null;
}
Full Program ..
Designing window is :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace image_upload
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//OpenFileDialog obj = new OpenFileDialog();
// obj.Filter =
}
private void button2_Click(object sender, EventArgs e)
{
foreach (Control txt in this.Controls)
{
if (txt.GetType() == typeof(TextBox))
if (!string.IsNullOrEmpty(txt.Text))
txt.Text = null;
}
textBox1.Focus();
}
}
}
If condition only to set null to text box if you want to reset all the field then remove this or comment
like
foreach (Control txt in this.Controls)
{
// if (txt.GetType() == typeof(TextBox))
if (!string.IsNullOrEmpty(txt.Text))
txt.Text = null;
}
textBox1.Focus();
so you can apply following codes in your project ..
foreach (Control txt in this.Controls)
{
if (txt.GetType() == typeof(TextBox))
if (!string.IsNullOrEmpty(txt.Text))
txt.Text = null;
}
Full Program ..
Designing window is :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace image_upload
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//OpenFileDialog obj = new OpenFileDialog();
// obj.Filter =
}
private void button2_Click(object sender, EventArgs e)
{
foreach (Control txt in this.Controls)
{
if (txt.GetType() == typeof(TextBox))
if (!string.IsNullOrEmpty(txt.Text))
txt.Text = null;
}
textBox1.Focus();
}
}
}
If condition only to set null to text box if you want to reset all the field then remove this or comment
like
foreach (Control txt in this.Controls)
{
// if (txt.GetType() == typeof(TextBox))
if (!string.IsNullOrEmpty(txt.Text))
txt.Text = null;
}
textBox1.Focus();
Set all textbox value null or empty at a time using foreach !!
Reviewed by Unknown
on
00:47
Rating:
No comments: