How to make Simple Phone Book

How to make Simple Phone Book



Code

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 PhoneBook
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "" && maskedTextBox1.Text.Length < 11)
                MessageBox.Show("Enter Data in all fields");
            else
            {
                dataGridView1.Rows.Add(textBox1.Text, textBox2.Text, maskedTextBox1.Text);
                textBox1.Text = "";
                textBox2.Text = "";
                maskedTextBox1.Text = "";
                textBox1.Focus();
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            textBox3.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            textBox4.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            maskedTextBox2.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DialogResult Result = MessageBox.Show("Do you really want to Delete???", "Confirmation", MessageBoxButtons.YesNo);
            if (Result == DialogResult.Yes)
            {
                dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "" && textBox4.Text == "" && maskedTextBox2.Text.Length < 11)
                MessageBox.Show("Enter Data in all fields");
            else
            {
                dataGridView1.SelectedRows[0].Cells[0].Value = textBox3.Text;
                dataGridView1.SelectedRows[0].Cells[1].Value = textBox4.Text;
                dataGridView1.SelectedRows[0].Cells[2].Value = maskedTextBox2.Text;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }

}


Screen Shot

How to make Simple Phone Book

Popular posts from this blog

Real marksheet using HTML

Salary Calculate Application in C#