Example : How to Clean/Clear/Reset/Cancel the C# Elements or Controls data.
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CmbNationality.Items.Add("Select One");
CmbNationality.Items.Add("India");
CmbNationality.Items.Add("USA");
CmbNationality.Items.Add("SriLanka");
CmbNationality.Items.Add("Bhutan");
CmbNationality.Items.Add("Nepal");
CmbNationality.Items.Add("Other");
// No item selected initially
//CmbNationality.SelectedIndex = -1;
// First item selected initially
CmbNationality.SelectedIndex = 0;
Clear();
}
private void UrBtnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Clear()
{
TxtSlno.Text = "";
TxtUserId.Clear(); //TxtUserId.Text = "";
TxtAddress.Clear();
TxtPass.Clear();
TxtCPass.Clear();
TxtMob.Text = "";
DtpDob.Value = DateTime.Today;
RdbMale.Checked = false;
RdbFemale.Checked = false;
RdbOther.Checked = false;
ChkNonMatric.Checked = false;
ChkMatric.Checked = false;
ChkItermediate.Checked = false;
ChkGradPostG.Checked = false;
// First item selected initially
CmbNationality.SelectedIndex = 0;
// No item selected initially
//CmbNationality.SelectedIndex = -1;
// to remove typed text
//CmbNationality.Text = "";
RtbRemarks.Text = "N/A";
//RtbRemarks.Text = ""; //Rich text box
//RtbRemarks.Clear();
//listBox1.ClearSelected();
//listBox1.Items.Clear();
//pictureBox1.Image = null;
//label1.Text = "";
TxtSlno.Focus();
}
private void UrBtnClear_Click(object sender, EventArgs e)
{
Clear();
}
}
}
![]()
0 Comments