My datagridview itemDelete function:
this.dgv_items.RowsRemoved += this.dgv_items_itemDelete;
private void dgv_items_itemDelete(object sender, DataGridViewRowsRemovedEventArgs e)
{
try
{
int row = e.RowIndex;
string name = dgv_items.Rows[row].Cells[0].Value.ToString();
deleteFromDB(name);
}
catch (Exception) { }
}
But by the time we reach this code, the row will have been removed, meaning dgv_items.Rows[row].Cells[0].Value gets the value if the row next in line.
I want to get the Cells[0] value of the removed row, so I can remove the item from the database file as well. How can I achieve this?
You could handle the
UserDeletingRowevent instead. Note that it supports event cancelation.