RickZeeland is right. I post this second solution with a slight correction from the code you showed:
private void dgvwDtls_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > -1) {
ChqMngrBsns.Masters.BankInfo bnkinfo = new ChqMngrBsns.Masters.BankInfo();
bnkid = Convert.ToInt32(dgvwDtls.Rows[e.RowIndex].Cells["bankid"].Value);
if (dgvwDtls.Columns[e.ColumnIndex].Name == "Edit")
{
txtBnknm.Text = dgvwDtls.Rows[e.RowIndex].Cells["bankname"].Value.ToString();
string CTS = dgvwDtls.Rows[e.RowIndex].Cells["Chequetype"].Value.ToString();
if (CTS == "True")
{
rbchqtype1.Checked = true;
}
else if (CTS == "False")
{
rbchqtype2.Checked = true;
}
txtAcntno.Text = dgvwDtls.Rows[e.RowIndex].Cells["Accountno"].Value.ToString();
cmbAcntype.Text = dgvwDtls.Rows[e.RowIndex].Cells["Accounttype"].Value.ToString();
Isinsert = false;
}
else if (dgvwDtls.Columns[e.ColumnIndex].Name == "Delete")
{
bnkid = Convert.ToInt32(dgvwDtls.Rows[e.RowIndex].Cells["bankid"].Value);
DialogResult dr = MessageBox.Show("Are you sure to delete row?", "Confirmation", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
bnkinfo.DeleteData(bnkid);
}
else if (DialogResult == DialogResult.No)
{
MessageBox.Show("Nothing Deleted");
}
LoadDataGridView();
}
}
}
If you place the test of the RowIndex at the beginning, you get an early exit of the method. Strange that the CellContentClick event is fired when you click on a column header, though.