Hello,
I have a working application that sits on the grid's "RecordManager.Current.CollectionChanged" event and when it sees that the previously selected item has been removed selects the next one. This is a workflow aid for the user.
I recently noticed that this event doesn't appear to be what I thought it was, and is probably not the best hook.
Additionally, I realized that my logic was being called thousands of times as the grid is initially loaded up. Removing the hook improved performance immensely.
I'm now hoping to find a more appropriate hook.
I am surprised to see the "RecordsDeleted" event is not fired when the selected item is removed from the datasource, even though it is clearly removed from the screen.
Thanks for any suggestions!
It is a built-in behavior for the XamDataGrid to activate the next record when the currently active is deleted. Do you not see this behavior by default? I am attaching a sample project with hooked up Records collection and the source collection changed events. They get fired when deleting/adding records with the respective action. This is true when you add/remove item from the UI and from code.
Hi Alex. What do you mean by "Records' collection COllectionChanged event"? I hooked into the mentioned CollectionChanged event on the recordmanager. This "auto next" logic is UI specific, so I believe the code needs to live there and be isolated. The back end data source doesn't know about the grid. In theory I could have the view model (data context for the view) raise an event and add code to watch for that.
Honestly, I don't understand why the selection changed event doesn't handle this situation. If I've got an item selected and that item is removed from the data source, why doesn't this event get raised? Clearly, my selection has changed from something to nothing, right?
Have you tried using the Records' collection CollectionChanged event or your underlying source collection's CollectionChanged event? It would probably be best if you hook up to that event in the Loaded event of the XamDataGrid so that to avoid the initial calls.
RecordsDeleted will be fired only when a record is deleted from the XamDataGri's UI. This event will not fie when it is being removed from the underlying source. Events like Sorting/Grouping etc are being invoked in the same fashion.