Error savinig entities

Posts   
 
    
Posts: 8
Joined: 23-Apr-2005
# Posted on: 28-Apr-2005 17:03:37   

I have an odd behavior occurring...

Setup: LLBLGen 2004.2, Whidbey beta 2

I have a child DataGridView associated with (bound to) a child collection that is a part of my maiin collection. I enter a new item, then hit enter to come down to the nxt row.

When I attempt to save, the SaveEntity is failing b/c it picks up the new row I "entered" down to. In my mind, with databinding it should only pick up the row where I entered all the data into.

I have tried SaveCollection and SaveEntity - same result.

I have tried only cycling through the DirtyEntities - that does the same thing.

TIA,

Chris

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-Apr-2005 17:54:32   

Nice huh, databinding wink .

Grids behave differently, depending on the brand of grid. WHen you add a new row by simply positioning the cursor on the row, and move the cursor back up without adding any data, the row should dissapear. Though some grids leave it as is.

When you're at the new row after you've pressed enter, hit ESC. this should remove the new row.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 8
Joined: 23-Apr-2005
# Posted on: 28-Apr-2005 18:18:48   

Thanks Frans,

I don't believe it's an issue with the DataGridView behaving improperly.

What I'm concerned about is in my "Save" code for the underlying collection for the DataGridView. I am attempting to save the collection, entity by entity - dirty ones only - not the entire collection.

I'm confused because the DataGridView seems to have created a new entity (empty) in the underlying collection, and my subsequent "Save" logic is trying to save it.

Under normal circumstances, this DataGridView works normally. When I fill all the fields in the object and then Save it without leaving the row, it works fine. This is an edge case that only occurs when the user fills all the fields in the DataGridView and at the last field, once they fill it in, they tab again (tab off the row onto a new one).

When you then click to save, the underlying collectin has both the newly added (and filled) row, as well as the fresh empty one.

Maybe this is just by default with the data binding logic of the DataGridView ... not sure. I would have assumed that the new object would not get persisted to the collection until either an explicit EndEdit/CommitEdit/etc. occurs by my code or implicitly by tabbing off the row.

My (ugly hack stuck_out_tongue_winking_eye ) solution is to check the collection when I first enter my Save method and remove any objects that appear to be empty. I test several properties I know should have contents to determine whether to remove it.

Am I missing anything here?

Chris

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 28-Apr-2005 19:57:33   

Hi, Chris. I'll have to second Frans' thought that this is a databinding problem. I use the Infragistics grid, and in the exact same scenario as long as no new data in entered into the new row, an entity is not added to the datasource. Looks to be just the mechanics of your grid. simple_smile

Jeff...

Posts: 8
Joined: 23-Apr-2005
# Posted on: 29-Apr-2005 04:57:02   

Thanks guys!

smile