我的表单中有一个 dataGridView ,其中有一列按钮。我想在只有一个按钮单击时执行一些代码。我试图写下面的代码,但是当我点击列的标题时,块中的写入代码被执行。有人能帮我吗?
private void UpDatedataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show(UpDatedataGridView2.CurrentCellAddress.ToString());
if (UpDatedataGridView2.RowCount > 0)
{
if (UpDatedataGridView2.CurrentCell.Value.ToString().Trim() == "delete Record")
{
if (DialogResult.Yes == MessageBox.Show("Are you sure to delete the record", "Delete", MessageBoxButtons.YesNo))
{
UpDatedataGridView2.ReadOnly = false;
UpDatedataGridView2.AllowUserToDeleteRows = true;
string number = UpDatedataGridView2.CurrentRow.Cells[1].Value.ToString();
da.DeleteCommand.CommandText = "Delete from tblKala where ID =" + number;
conn.Open();
da.DeleteCommand.ExecuteNonQuery();
conn.Close();
dataGridView1.ReadOnly = true;
UpDatedataGridView2.DataSource = SelectData();
MessageBox.Show("Deleting done !");
}
}
}
}