Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum

CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • More Windows DataBinding Woes

    rated by 0 users
    Answered (Not Verified) This post has 0 verified answers | 22 Replies | 3 Followers

    Top 150 Contributor
    62 Posts
    NickTaylor posted on Thu, Sep 9 2010 5:47 AM

    Can anyone tell me where I am going wrong please...?

    My problem relates to WinForms databinding and its relationship with a CSLA business object. In fact its CSLA business objects that in turn contain child collections that are really causing me trouble.

    I fully understand about the need to disconnect the BO from the UI at the point I wish to cancel or revert changes. There are lots of examples in Rocky's book to demonstrate this. However to make for a pleasing user experience I need to invoke the following functionality.

    1). Load the appropriate business object ( and its child collections ). The form obviously contains parent and child bindingsources.

    2). Begin the edit.

    3). Let the user make as may changes as they like to the BO and any of its child members.

    4). Allow the user to save or revert ALL the changes made since the start of the edit session on the current BO. ( so I only want to be able to save/rollback at the parent level )

    The only way that I can make this scenario work is to set DisableIEditableObject to true on both the parent and the child business objects. That way I have complete control over when BeginEdit(), ApplyEdit(), or CancelEdit() are called. If I dont do this for some reason the child edit levels get out of sync with the parent ( caused during child navigation via a datagrid no doubt ), and when I call CancelEdit() on the parent, it throws an exception.

    I know Rocky says that setting DisableIEditableObject is the wrong road to take and he is ( as always ) right, as some of my bound windows components don't seem to update quite properly with this setting enabled. Surely I dont have to start drilling down into the children and calling CancelEdit() on each one of them do I ?

    So, how do I control a save / undo process at the parent level only ?

    Sorry if this is going over old ground, but I find windows databinding really frustrating! Crying



    All Replies

    Top 10 Contributor
    2,279 Posts
    JonnyBee replied on Sun, Oct 31 2010 11:32 PM


    The Save method actually returns a new instance of your root object (and structure) as the result of  Save so you code should be:

    _Root = _Root.Save();

    That should fix it.

    Jonny Bekkum, Norway CslaContrib Coordinator

    Not Ranked
    13 Posts

    Thanks Jonny. you solved my problem.....

    Not Ranked
    12 Posts

    Hi jonny, do you know why in RootChildGrandchildWinFormTest example this code is needed?

      void childrenBindingSource_CurrentChanged(object sender, EventArgs e)

    how does it works?

    Not Ranked
    13 Posts

    it solved the problem for ParentChild Relation....

    But not for parentChildGrandchild Relation...

    When i use

    _Root = _Root.Save(); for oneParent with Multiple children it work fine.

    but when i use it for one parent with multiple children further multiple grandchildren for children it dont marks the _Root.IsDirty to false....

    Top 10 Contributor
    2,279 Posts

    Then you should inspect your object graph to find which object(s) are Dirty

    Could be some ValidationRule or Save code that sets a value and makes the object dirty.

    Jonny Bekkum, Norway CslaContrib Coordinator

    Not Ranked
    11 Posts


    I am using the above  helper extension methods in my apps as well, but what I would like to know is if it is possible to cancel the entries without having to unbind and then bind datasources again.

    I have something like this in my code

    case actionList.Cancel:        




                  if (_receipt.IsNew)

                    _receipt = null;


                    _receipt = Receipt.GetEditableRoot(_receipt.Id);








    What I would like is to simply call _receipt.CancelEdit() and all entered data in the grids to be erased without having to rebind the datasources again.  I am running into performance issues when unbind/rebind datasources.

    Thanks in advance,


    Top 10 Contributor
    2,279 Posts


    You should think about this as your list may have edited items, removed items and added/new items.

    So would it be faster to raise a LOT of changed events inline with the UI or do a restore without the UI? I'd say the last alternative is a LOT safer (and maybe even the first is impossible to get the sequence correct as items must be reordered as well).

    So the fastest solution should be


    • restore list with no UI (and no events to force an update of the UI as this would slow down the process)
    • tell the binding source to rebind/reset the list and make the UI components reread the items of the list. 


    So when you run into performance issues you should look at the events and handling in the UI and/or inspect the design of your form if there is a LOT of data retrieved that cause the app to have poor performance. 

    Oh, I noticed that you get the object again in Cancel. I would suggest that you look at the N-level undo mechanism. See other posts here on the forum as well - as this will allow you to create a snapshot and later restore the snapshot in a cancel operation.

    Jonny Bekkum, Norway CslaContrib Coordinator

    Not Ranked
    11 Posts
    Tatjana replied on Wed, Jul 24 2013 12:26 PM


    Thank you for your quick answer; I will do more research on the "N-level undo mechanism" and see if that will help me fix the issue I am dealing with.  


    Page 2 of 2 (23 items) < Previous 1 2 | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems