delete multiple lines in DataGrid, message always shown deleting the first line

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

private void dt_RowDeleted(object sender, DataRowChangeEventArgs e)
{
int id= (int)e.Row["id", DataRowVersion.Original];

if(id >5)
{
e.Row.RejectChanges();
MessageBox.Show(this, "Can not delete!" + id);
}

}


When multile lines are selected and deleted from the datagrid by using
delete key.

The warning message showned by MessageBox.Show() always same. id never
changed, always the firt one.

Is this a known bug, any work around?

Thanks a lot!
Ryan Liu
 
Don't know if it applies in this case & don't have the details handy, but
whenever I've had to delete multiple rows, you have to start at the last one
and work your way up. Something about the id changing if you delete working
down
 
I think this is very good point.

But it is out of my contorl. Deleteing multiple line by "Del" key and
raising deleted event are both build-in function of datagrid.

Maybe Microsoft should take your suggestion into account.

Ryan Liu


Taras said:
Don't know if it applies in this case & don't have the details handy, but
whenever I've had to delete multiple rows, you have to start at the last one
and work your way up. Something about the id changing if you delete working
down

Ryan Liu said:
private void dt_RowDeleted(object sender, DataRowChangeEventArgs e)
{
int id= (int)e.Row["id", DataRowVersion.Original];

if(id >5)
{
e.Row.RejectChanges();
MessageBox.Show(this, "Can not delete!" + id);
}

}


When multile lines are selected and deleted from the datagrid by using
delete key.

The warning message showned by MessageBox.Show() always same. id never
changed, always the firt one.

Is this a known bug, any work around?

Thanks a lot!
Ryan Liu
 
Back
Top