Weird behaviour with DataGridView and Child Object (I have searched before posting...)

Weird behaviour with DataGridView and Child Object (I have searched before posting...)

Old forum URL: forums.lhotka.net/forums/t/2554.aspx


Aliator posted on Monday, March 19, 2007

I have an Order class (EditableRoot) with a child class OrderLine(EditableChild) driven by OrderLineList(EditableChildList).

In the WinForm, I have TextBoxes for Order's properties and a DataGridView for OrderLine's properties.

My WinForm is designed to put '*' at the end of the title bar when an object is dirty, so I see inmediatly if changes are well managed...

So, I open my Order management form, and when I edit a cell of the DataGrid [OrderLine(EditableChild)], I see the Order[(EditableRoot)] object is dirty. I save, check in the database, and I see change was commited. There's no '*' in the title bar, so Order object is no dirty.

I now I update a cell OrderLine(EditableChild) again... Order[(EditableRoot)] object is not marked as dirty...

I change a property of Order, then I see again '*' in the title bar and if I save, the whole data is succesfully commited to DB...

Something is happennig after saving Order object, but I can't see what...

So, if I edit a cell of the child object and save, I need to make changes in the parent, save, and the the child becomes responsive again...

What am I missing ?

BTW, this is the code I use for saving (pretty standard...):

/*------------------------------------------------------------------------*/
this.OrderBindingSource.RaiseListChangedEvents = false;
this.OrderLineBindingSource.RaiseListChangedEvents = false;

Order _temp = mBo.Clone();

_temp.ApplyEdit();

    mBo = _temp.Save();
    mBo.BeginEdit();

    this.OrderBindingSource.DataSource = null;
    this.OrderLineBindingSource.DataSource = this.OrderBindingSource;
    this.OrderBindingSource.DataSource = mBo;
    
    this.OrderBindingSource.RaiseListChangedEvents = true;
    this.OrderLineBindingSource.RaiseListChangedEvents = true;

/*------------------------------------------------------------------------*/

RockfordLhotka replied on Tuesday, March 20, 2007

While PropertyChanged events in the child objects cause a ListChanged from your list automatically, you have to write code in your editable root to handle ListChanged and raise a PropertyChanged from the editable root. This could be part of your problem.

Also, make sure you are calling MarkOld() in your child objects. The data portal calls it for you on the root object, but you need to do this yourself in the child objects.

Aliator replied on Tuesday, March 20, 2007

Fixed.

As you said, I wasn't handling correctly the list of changed properties.

Thank you !!!

Vinodonly replied on Tuesday, April 03, 2007

i'm facing the same problem as mentioned in the original post but not sure how to implement the suggestion which you have given.

 

can you point me towards some code or reference in the book to solve this problem..

Copyright (c) Marimer LLC