
如上图:
CellContentClick获取dataGridView行索引有时准确有时又不准确,如上图,行索引还记录的上一次点击单元格的行索引
代码如下:
//获取dataGridView行索引:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
RowID = e.RowIndex;
}
private void TS_Del_Click(object sender, EventArgs e)
{
if (RowID > -1)
{
DialogResult Result = MessageBox.Show("确定要删除: "+this.dataGridView1.Rows[RowID].Cells [2].Value+" 吗?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if(Result==DialogResult.OK)
{
ds.Tables["typeA"].Rows[RowID].Delete();
SqlCommandBuilder Builder = new SqlCommandBuilder(ADP);
ADP.Update(ds.Tables["typeA"]);
ds.Tables["typeA"].Clear();
getdate();
}
}
else
{
MessageBox.Show("索引ID不能为-1!","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
}
}