S
Sergiy_Vakshul
Guest
Hi,
I’ve got a DataGridView.
When a user selects a row and clicks Delete button the row has to be deleted from the database.
Actually I’ve got it working now.
On UserDeletingRow event of the DataGridView the data is being validated and the process can be canceled if necessary.
On UserDeletedRow event to send changes to the database I use:
TableAdapter.Update(SSDataSet);
dr.AcceptChanges();
As I said it works.
The trouble happens if due to concurrency conflict the row can’t be deleted from the database.
What we have now is:
- The row isn’t deleted from the database,
- The row isn’t removed from the DataTable
- The row IS deleted from the DataGridViewRowCollection
So there is no record in the DataGridView anymore which is not as it should have been.
On UserDeletedRow event using dr.RejectChanges() I can change the RowState of the row from Deleted to Unchanged but I am stuck at how to insert the same row back to the DataGridViewRowCollection.
I tried something like:
DataGridViewControl.Rows.Insert(deletedRow.Index, deletedRow.Row)
It won’t work with binding data.
Performing Update on UserDeletingRow event won’t send a corresponding command to server that’s why I decided updating on UserDeletedRow instead of UserDeletingRow event.
I can’t see any suitable approach so far. Can you?
Continue reading...
I’ve got a DataGridView.
When a user selects a row and clicks Delete button the row has to be deleted from the database.
Actually I’ve got it working now.
On UserDeletingRow event of the DataGridView the data is being validated and the process can be canceled if necessary.
On UserDeletedRow event to send changes to the database I use:
TableAdapter.Update(SSDataSet);
dr.AcceptChanges();
As I said it works.
The trouble happens if due to concurrency conflict the row can’t be deleted from the database.
What we have now is:
- The row isn’t deleted from the database,
- The row isn’t removed from the DataTable
- The row IS deleted from the DataGridViewRowCollection
So there is no record in the DataGridView anymore which is not as it should have been.
On UserDeletedRow event using dr.RejectChanges() I can change the RowState of the row from Deleted to Unchanged but I am stuck at how to insert the same row back to the DataGridViewRowCollection.
I tried something like:
DataGridViewControl.Rows.Insert(deletedRow.Index, deletedRow.Row)
It won’t work with binding data.
Performing Update on UserDeletingRow event won’t send a corresponding command to server that’s why I decided updating on UserDeletedRow instead of UserDeletingRow event.
I can’t see any suitable approach so far. Can you?
Continue reading...