I got a DataGridView which just allows user to delete rows (with no direct editing or adding on DataGridView). I will update my database information whenever user deletes rows on DataGridView (there is no binding among DB and gridview).
I have no problem to have deleting row when user is deleting only one row using DeletingRow event like below:
private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
DataGridViewRow row = e.Row; //only single row
}
However i could not capture list of all rows when user selects multiple rows and delete them. Above event only called once for first row only. In order to handle this case i did set dataGridView1.MultiSelect = false;
however this is a workaround!
So how can i have list of all selected rows which user is deleting, currently?
All selected rows will be available at dataGridView1.SelectedRows
so you can do something like:
void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
{
this.HandleRowDeletion(row);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments