简体   繁体   中英

Mark row as deleted in dataTable on UserDeletingRow

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?

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.

在集合中捕获“待删除” rowId,然后创建一些方法并传递该集合以处理记录的删除

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM