h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Error Provider in Windows Application

Error Provider is a very useful for Application Validation.
Create Simple form.
Drag and Drop two Text Boxes and Buttons.
TextBox Names are txtUsername,txtPassword
Button Names are btn_Ok,btn_Cancel.
Button Text are &Ok,&Cancel.
Copy and Paste the following code in your Coding Section

 private void btn_Cancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void btn_Ok_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text.Length == 0 && txtPassword.Text.Length == 0)
            {
                DispayErrorProvider(txtUserName);
                DispayErrorProvider(txtPassword);
            }
            else if (txtUserName.Text.Length == 0 )
            {
                DispayErrorProvider(txtUserName);
            }
            else if (txtPassword.Text.Length == 0)
            {
                DispayErrorProvider(txtPassword);
            }
            else
            {
                MessageBox.Show("Validate successfully");
            }
         }
        private void txtUserName_TextChanged(object sender, EventArgs e)
        {
            DispayErrorProvider(txtUserName);
        }
        void DispayErrorProvider(TextBox txt)
        {
            if (txt.Text.Length > 0)
            {
                errorProvider1.Clear();
            }
            else
            {
                errorProvider1.SetError(txt, "Input doesn't Empty");
            }
        }
        private void txtPassword_TextChanged(object sender, EventArgs e)
        {
            DispayErrorProvider(txtPassword);
        }
        private void txtUserName_Leave(object sender, EventArgs e)
        {
            DispayErrorProvider(txtUserName);
        }
        private void txtPassword_Leave(object sender, EventArgs e)
        {
            DispayErrorProvider(txtPassword);
        }

Run the Application.
Press Alt+O Button .Error Provider will display in the Screen.
Press Alt+C Application will exit.
Type your User name and Password .Error provider will not display in the Screen.
Note Use Only Keyboard.

Pass TextBox values from One Form to another form Datagridview

                Today we will discuss about Pass TextBox value into another form DataGridview using C#.Net Language. Here we used 2 Class Files and Two Form. 2 Class Files are ClsAddintoiTable and ClsBL. Two forms are Form1 and Form2.
Class Name: ClsAddintoiTable
namespace DatagridviewTasks { class ClsAddintoiTable { DataTable dt; public DataTable Addintotable(ClsBL cls) { dt = new DataTable(); dt.Columns.Add("First Name"); dt.Columns.Add("Last Name"); DataRow dr; dr = dt.NewRow(); dr["First Name"] = cls.FirstName; dr["Last Name"] = cls.LastName; dt.Rows.Add(dr.ItemArray); return dt; } } }
Class Name: ClsBL
namespace DatagridviewTasks { class ClsBL { private static string _FirstName; private static string _LastName; public string FirstName { get { return _FirstName; } set { _FirstName = value; } } public string LastName { get { return _LastName; } set { _LastName = value; } } } }
Form 2
private void button1_Click(object sender, EventArgs e) { cls.FirstName = textBox1.Text; cls.LastName = textBox2.Text; clsAdd.Addintotable(cls); this.Close(); } public DataTable CopyValue() { DataTable dt1 = new DataTable(); dt1 = clsAdd.Addintotable(cls).Copy(); return dt1; }
Form 1
DataTable dt; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 frm = new Form2(); dt = frm.CopyValue(); dataGridView1.DataSource = dt; } private void button2_Click(object sender, EventArgs e) { Form2 frm = new Form2(); frm.ShowDialog(); }

Shortcut key for Button in Windows Application

              Validation is an important portion in the Application Side.Some User wants to use Keyboard .So I give this Code for Shortcut Key for Button in Windows Application.
Step by step Procedure:
Create Form.
Drag and Drop your Button in the Form.
Give a name for button(like btn_Ok)
Give a text for button (like this &ok)
Click the Button.

 private void btn_Ok_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Thank you");
        }



 Run your Application .

Click Alt+O Key
MessageBox will display.