Click here to Skip to main content
14,697,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
On RowHeaderMouseClick I want load details
On RowHeaderMouseDoubleClick I want delete reocrd

But the problem is when i double click on row header it also firing RowHeaderMouseClick event also

My Code is like this
private void dg_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                try
                {
                    intBankId = int.Parse(dg.Rows[e.RowIndex].Cells["BankId"].Value.ToString());
                    txtBankName.Text = dg.Rows[e.RowIndex].Cells["BankName"].Value.ToString();
                    txtNote1.Text = dg.Rows[e.RowIndex].Cells["Note1"].Value.ToString();
                    txtNote2.Text = dg.Rows[e.RowIndex].Cells["Note2"].Value.ToString();
                    txtNote3.Text = dg.Rows[e.RowIndex].Cells["Note3"].Value.ToString();
                    btnSave.Text = "Update";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error on load records :" + ex.Message);
                }
            }
        }

private void dg_RowHeaderMouseDoubleClick(object sender,DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                try
                {
                    intBankId = int.Parse(dg.Rows[e.RowIndex].Cells["BankId"].Value.ToString());
                    string ans = MessageBox.Show("Are sure want to Delete Record?", "Confirm", MessageBoxButtons.YesNo).ToString();
                    if (ans.Equals("Yes"))
                    {
                        obj.con.Open();
                        cmd = new OleDbCommand("delete from Banks where BankId=" + intBankId + "", obj.con);
                        cmd.ExecuteNonQuery();
                        obj.con.Close();
                        intBankId = 0;
                        FillGrid();
                        MessageBox.Show("Record deleted successfully");
                        Clear();
                        txtBankName.Focus();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error on delete record :" + ex.Message);
                }
            }
        }
Posted
Updated 15-Aug-12 7:54am
v2

1 solution

   
v2
Comments
Ravi Sargam 16-Aug-12 12:17pm
   
Kenneth, can you explain how to use it ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900