I want to display a list of self-tracking entities on the form, using standard binding mechanism.
What I want is to select entites from list, change/add or remove them, then either submit changes or reject them depending on user choice.
As far as I understand, for that the list of entities should be attached to the context, then an accept changes call should be made (or not, if the changes are to be rejected). That means that deleted entities must be in the list as well, marked as deleted.
However, they shouldn't be displayed anymore. That means display should be filtered by the state of entities.
Now, usually to do filtering I will wrap my list in BindingList and use the Filter property. From the other hand, entites do not immediately expose their sate (unlike typed data rows) and hold them in ChangeTracker.State. I am at loss, how to do the filtering in this case, especially considering state is an enum, not a plain type.
After some deliberation, I found that
BindingListdoes not support filtering, and the same is technically true forBindingSource.So, with standard filtering out of question, I wrote my own implementation, like this:
With this, I can bind to the list, add and delete as much as I want, and ofr commit purposes retrieve all records, including dead ones, with GetAllForSubmit().