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.
According to the following post on MSDN, this user was experiencing the same problem.
http://social.msdn.microsoft.com/Forums/en-US/a88fec61-880c-403d-8d3a-f1898f9837fe/problem-when-binding-entity-framework-objects-to-infragistics-ultrawingrid?forum=adodotnetentityframework
To quote the relevant section...
"when starting entering a new item it is added to the bindingsource but not to the collection (this is explicilty done in System.Data.Objects.OblectViewEntityCollection<TViewElement, TItemElement>.Add(TViewElement, bool). Only if the Position-property of the CurrencyManager is changed (by navigation to a sibling row), the new item is added to the EntityCollection. But this doesn't happen, if the user firt clicks to another part of the grid. The after reentering the childband, where the item was added, the new row dissapeares."