views:

201

answers:

2

I have a datatable bound to a winforms dataGridView via a BindingSourceControl. I want to be able handle the UserDeletingRow event from the dataGridView and mark the row in my dataTable as deleted. I need to then be able to retrieve the rows marked as deleted from the datatable so that I can delete them from my database when a Save button is clicked. Please not I dont want to delete from the database on each firing of UserDeletingRow, only mark that row as deleted in my dataset.

Can anyone point out how to do this?

+1  A: 

Capture the "to be deleted" rowId(s) in a collection then create some method and pass the collection to handle the deletion of the records

Avien
A: 

The best I found to do this is be sure to call AcceptChanges() on the dataTable/dataset before editing starts - I did this on form load when the data was bound to the grid. Now when the user deletes records via the grid and then hits "save", I am able to filter the rows in the dataTable by the row's rowState to get the ones that have been deleted. Note that the Count property on the rows collection of dataTable drops by one each time the user deletes a row, but the row is still in the dataTable, its just marked for deletion.

Dav Evans