I have a C# winforms app that in the ultraToolbarManager click event fires the following code when the user clicks the DELETE button in the toolbar:
myGrid.PerformAction(UltraGridAction.DeleteRows);
This works fine for most scenarios. Now though, I have some child records that need to be deleted as well. In order to delete these child records through a custom routine, I need to pull a key value from one of the columns of each deleted row (you can delete multiple rows at once in the grid).
First, I need to know if the user deleted the records or if they canceled. Is there a way through code to do this or do I have to have logic in the AfterRowsDeleted event to account for this?
Second, how do you determine what rows were deleted?
Ok, one approach would be to handle the UltraGrid.BeforeRowsDeleted event.
What i usually do in such an scenario would be to replace the build in delete dialog, thus i have information what the user finally decided. (As i have row information at that time i just show an modal dialog at the start of the event including some extended info about what the user actually wants to delete).
Then, depending on the modal dialog return, i either cancle the event or i handle my data stuff like deleting child rows first, maintaining integrity, logs and such. As the data is still fully available at that point, the rows are not yet actually deleted but i know that the user wants to delete them i have full freedom. Usually i cancle the event anyway in the end, and take care of of deleting or mark the "main rows" as deleted in the datasource myself and let the grid just sync.
I agree, however in my case that is not an option due to the way our data is stored in such a way that using the DataSet would not work.
Not that it couldn't be solved on the grid level, but you might consider to implement such stuff on the datasource level?
Like let's say you bind to an DataSet and handle the things that have to be done on row deleting in the dataTable.RowDeleting event.
Kinda more "central" and you don't need to worry about "how" the user interface deleted it.