Haimanti 0 Newbie Poster

hi

i have retrieved data on data grid from backend.

i want to write a code with which i will be able to retrieve the complete data related to the editable field from backend to front end. The edit and delete button needs to be seen on the right click over any of the field in the data grid.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Try_WindowsApplication1
{
    public partial class frmViewCustData : Form
    {
        private int col = -1;
        private int row = -1;
        ToolTip tt1 = new ToolTip();
        SqlConnection conn1 = new SqlConnection("Server=mosipl06;uid=sa;pwd=mosindia; Initial Catalog=Haimanti");
        string a = ("");

        DataSet ds = new DataSet();

        public frmViewCustData()
        {
            InitializeComponent();
        }

        private void ViewData_Load(object sender, EventArgs e)
        {
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void butViewData_Click(object sender, EventArgs e)
        {
            if (conn1.State == ConnectionState.Closed)
                conn1.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("Select * from customer order by id", conn1);
            da.Fill(ds, "Customer");
            dataGridView2.DataSource = ds;
            dataGridView2.DataMember = "customer";
        }

        private void butEditData_Click(object sender, EventArgs e)
        {
            //frmInsertCustData frmInsertCustData = new frmInsertCustData();
            //frmInsertCustData.Show();

            //SqlDataAdapter da1 = new SqlDataAdapter("Update customer set @name = txtName.Text.Trim() where id = txtID.Text.Trim()");
            //DataSet ds1 = new ds1();

        }

        private void dataGridView2_MouseUp(object sender, MouseEventArgs e)
        {
            cxtMenuOptions.Show();

        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void frmViewCustData_Load(object sender, EventArgs e)
        {
            //assigning event
            //cutToolStripMenuItem.Click += new EventHandler(cutToolStripMenuItem_Click);
            //copyToolStripMenuItem.Click += new EventHandler(copyToolStripMenuItem_Click);
            //pasteToolStripMenuItem.Click += new EventHandler(pasteToolStripMenuItem_Click);

            editToolStripMenuItem.Click += new EventHandler(editToolStripMenuItem_Click);
            deleteToolStripMenuItem.Click += new EventHandler(deleteToolStripMenuItem_Click);
            //cxtMenuOptions.Items.AddRange(new ToolStripItem[] { cutToolStripMenuItem, copyToolStripMenuItem, pasteToolStripMenuItem, editToolStripMenuItem, deleteToolStripMenuItem });
        }

        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //frmInsertCustData frmInsertCustData = new frmInsertCustData();
            //frmInsertCustData.Show();
            //DataSet ds = new DataSet();
            //SqlDataAdapter da = new SqlDataAdapter("Select * from customer order by id", conn1);
            //da.Fill(ds, "customer");
            //row = e.RowIndex;
            //col = e.ColumnIndex;



        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //SqlDataReader dr1 = new SqlDataReader();
            //row = e.RowIndex;
            //col = e.ColumnIndex;


           //SqlDataAdapter da1 = new SqlDataAdapter("Delete from customer where @parameter =@value");
           // if (MessageBoxDefaultButton.Button1 = true)
           //     da1.ExecuteNonQuery();
           // else if (MessageBoxDefaultButton.Button2 = true)
           //     dataGridView2.Show();

            MessageBox.Show("Do you want to delete the record","Delete",MessageBoxButtons.OKCancel);
            DialogResult dialrslt = new DialogResult();
           frmInsertCustData myfrm = new frmInsertCustData();
            dialrslt = myfrm.ShowDialog();

            if (dialrslt == DialogResult.OK)
            {


                MessageBox.Show("Deleted Record!!");
            }

            else if (dialrslt == DialogResult.Cancel)
                MessageBox.Show("Action Reverted");


        }

        private void cxtMenuOptions_Opening(object sender, CancelEventArgs e)
        {

        }

        private void dataGridView2_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                row = e.RowIndex;
                col = e.ColumnIndex;

            }
        }

        private void cutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //dataGridView2.Rows[row].Cells[col].Value = Clipboard.GetData(DataFormats.Text);
            //dataGridView2.Rows[row].Cells[col].Value = "";

        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //if (row >= 0 && col >= 0)
            //    Clipboard.SetData(DataFormats.Text, dataGridView2.Rows[row].Cells[col].Value.ToString());
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //dataGridView2.Rows[row].Cells[col].Value = Clipboard.GetData(DataFormats.Text);
        }


    }
}