Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
205
New Row Not Committed to Data Source
posted

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

-> Address 1

-> Address 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.

Parents
No Data
Reply
  • 469350
    Offline posted

    What, exactly, do you mean when you say "click on another band?"

    Any action that causes focus to leave the current row and move to another row is essentially the same as far as the grid is concerned. In fact, the grid doesn't even really do much in either case. All it really does it change the Position on the BindingManager. This causes the BindingManager to call EndCurrentEdit, but the grid doesn't even do this directly.

    The type of data source you are doesn't matter as far as that behavior goes.

    So if you are clicking on any other row in the grid, then there should not be a problem, unless the DotNet Framework is specifically behaving differently with the EntityFramework.

    If you click outside of the grid, then that's a different story. The UpdateMode property of the grid determines what happens in that case, and by default, the grid behaves the same way when it loses focus. But if you are clicking on something like a toolbar button, which doesn't take focus away from the grid, then the grid would not commit that last edited row and that might be causing a problem here.

    If you want to try to work around the issue, you could try trapping Before/AfterRowDeactivate and explicitly calling grid.UpdateData to commit all changes in the grid.

    Beyond that, though, I think we'd need to see a sample project demonstrating the issue in order to tell you what's going on there for sure.

Children