I have an UltraGrid on a Windows form. This grid is hierarchical and is bound to a BindingSource which is bound to an EntityCollection (Entity Framework). This hierarchy is made up of people and addresses as follows:
Person 1
-> Address 1
-> Address 2
Person 2
Each set of addresses has a new row template available at the bottom for adding additional addresses. When I first enter the new row to add an address, a new address entity is created with an EntityState of Detached. If I tab to the next row, the EntityState is changed to Added. This is the proper behavior.
The problem is that if I use this new row to add an additional address and then click to another band instead of tabbing to the next row, the EntityState remains as detached and does not get saved to the database. Additionally, if I click back to the original address band, the address I just added disappears.
For example:
I add an address to a person...
Doe John
-> 123 Main Street (... I press tab to move to the next line and add a second address ...)
-> 456 Central Ave (... Instead of tabbing to the next line, I click to the addresses of another person ...).
Doe Jane
-> 789 Washington Ave (... Here.)
... If I then click back to the addresses for John Doe, the 456 Central Ave address disappears because I never tabbed off of that line.
How do I prevent this behavior.
Hell Jacob,
This has been addressed in service release version of WinForms_14.1.20141.2059. Have you had time to review if this fixes and do you have any additional questions at this time?
Thank you.
Hello,
I have opened a private case for you so that I can link it to an internal development issue. This way you will be notified automatically when a development issue is updated. The case number is CAS-135456-N1Q7H4. You will see it located here: https://ko.infragistics.com/my-account/support-activity
Let me know if you have any questions regarding this matter.
Hi Jacob,
That's a fair point, so I'm going to ask Infragistics Developer support to write this up for developer review. I can't promise anything. It might be that the EntityFramework is just not compatible with the kind of hierarchical binding that the WinGrid is architected for. But I'd like to investigate this further and see if maybe we can, if not fix it completely, at least expose some helper methods on the grid to make things easier.
Well, the only workaround I could come up with was to create a custom class that inherits from the UltraDataSource. I then provided methods in this class to interact with the entity context, handling creating, updating, and deleting the objects. Therefore, I grid has no direct interaction with the entity context - I control it all through the UltraDataSource. This required a great deal of extra code and should not be necessary, but it does work.
Mike, in response to your last message...yes, I did try using a BindingSource, as I stated in my original post, second sentence. I tried calling the UpdateData() method from several places, including directly when the Save button was clicked.
This same issue was reported back in 2010. I found posts all the way back to 2008 of people reporting issues when using the grid with the Entity Framework. Since Entity Framework is now on version 6 and seems to be where Microsoft is putting all of their effort (they aren't developing datasets any longer), perhaps you should start testing to make sure your controls work well with it.