Editing child object in seperate window?

Editing child object in seperate window?

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


ajj3085 posted on Thursday, September 17, 2009

Hi,

Using Csla 3.7. I have what I would like to be a child object (BLB). This collection could be large memory, and not used much, so I'd like to have it lazy loaded. The UI is WinForms, and when editing this list I'd like to open another window.

My question revolves around how to handle things so the edit levels stay synced. Since the list will be in a seperate window, and I want lazy loading, I can't setup a binding source like I would usually for a child list.

Is this feasible? How would I set this up when I try to save the root object? When the child window closes, do the EndEdit and unbind just this particular child list from the window, and no changes needed in the main form?

RockfordLhotka replied on Thursday, September 17, 2009

This is pretty hard due to the way WinForms data binding operates, unless this edit window is modal. That makes it possible at least.

Even with a modal form it is tough though, because the bindingsource for that form needs to be a child of the bindingsource on your main form. This pretty much means the bindingsource needs to be declared on the main form, and you'll pass a reference to that bindingsource to the modal edit form.

It probably helps if you also use the binding helpers Miguel wrote for CslaActionExtender, because then you can provide the modal form with a binding helper node associated with that child bindingsource. That way you can easily (and correctly) call Cancel() or Apply() as the modal form closes.

ajj3085 replied on Thursday, September 17, 2009

RockfordLhotka:

This is pretty hard due to the way WinForms data binding operates, unless this edit window is modal. That makes it possible at least.



Yes, my intention is that the form would be modal.

RockfordLhotka:

Even with a modal form it is tough though, because the bindingsource for that form needs to be a child of the bindingsource on your main form. This pretty much means the bindingsource needs to be declared on the main form, and you'll pass a reference to that bindingsource to the modal edit form.



This is the part that concerns me; I would expect that this setup would then cause the child collection property to be read, which defeats the purpose of the lazy loading. Or maybe it would only load if the binding source is used to display something?
RockfordLhotka:

It probably helps if you also use the binding helpers Miguel wrote for CslaActionExtender, because then you can provide the modal form with a binding helper node associated with that child bindingsource. That way you can easily (and correctly) call Cancel() or Apply() as the modal form closes.



Yes, I've been starting to use the BindingSourceNode and BindingSourceHelper, and they have simplfied some of the forms I already have, very useful.

pabloing900 replied on Thursday, December 10, 2009

Hi, I have the same problem ajj3085 but i am using a wizard . It is a headache.
This is my thread
http://forums.lhotka.net/forums/thread/37809.aspx
but i get nothing. 0 Answer :-(
In my first screen i show the root then the user press Next button and fill child info.
When the user click next button for me  or open/close a child form for you, we need to call applyedit without saving the bo and then rebind.
Then when the user close all forms for you or get finish screen wizzard for me, we can save the bo.
My code looks like this:


 Private Sub RebindUI(ByVal saveObject As Boolean, ByVal rebind As Boolean)

    ' disable events
    Me.ProjectBindingSource.RaiseListChangedEvents = False
    Me.ResourcesBindingSource.RaiseListChangedEvents = False
    Try
      ' unbind the UI
      UnbindBindingSource(Me.ResourcesBindingSource, saveObject, False)
      UnbindBindingSource(Me.ProjectBindingSource, saveObject, True)
      Me.ResourcesBindingSource.DataSource = Me.ProjectBindingSource

           
      ' apply or cancel changes
      If saveObject Then
        mProject.ApplyEdit()

      Else
        mProject.CancelEdit()
      End If

    Finally
      ' rebind UI if requested
      If rebind Then
        BindUI()
      End If

      ' restore events
      Me.ProjectBindingSource.RaiseListChangedEvents = True
      Me.ResourcesBindingSource.RaiseListChangedEvents = True

      If rebind Then
        ' refresh the UI if rebinding
        Me.ProjectBindingSource.ResetBindings(False)
        Me.ResourcesBindingSource.ResetBindings(False)
      End If
    End Try

  End Sub

In form_closing event of your last form you need to call save method. The trick is donĀ“t call save method and call  BO.ApplyEdit() each time you show or close a form so you business object(BO) is always in consistent state. In the code you must to call RebindUI(true,true).

Copyright (c) Marimer LLC