我有以下代码加载我的 Windows 窗体:
private void Panou_Load(object sender, EventArgs e)
{
List<string>[] list;
list = Conexiune.Select();
dataGridView1.Rows.Clear();
(dataGridView1.Columns[3] as DataGridViewComboBoxColumn).DataSource = new List<string> { "", "activ", "inactiv", "neverificat", "blocat" };
for (int i = 0; i < list[0].Count; i++)
{
int number = dataGridView1.Rows.Add();
dataGridView1.Rows[number].Cells[0].Value = list[0][i];
dataGridView1.Rows[number].Cells[1].Value = list[1][i];
dataGridView1.Rows[number].Cells[2].Value = list[2][i];
dataGridView1.Rows[number].Cells[3].Value = list[3][i];
dataGridView1.Rows[number].Cells[4].Value = list[4][i];
dataGridView1.Rows[number].Cells[5].Value = list[5][i];
dataGridView1.Rows[number].Cells[6].Value = list[6][i];
}
}
一切正常,但现在我想在删除一行时在数据库中进行一些更新,所以我使用:dataGridView1_RowsRemoved。
例子:
private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
{
MessageBox.Show("deleted");
}
为什么表单加载时显示“已删除”消息?
dataGridView1.Rows[number].Cells[0].Value
包含来自数据库的 id。如何在dataGridView1_RowsRemoved
函数中检索此 id?