Edit level mismatch in CopyState (Yes again) - Winforms binding

Edit level mismatch in CopyState (Yes again) - Winforms binding

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


Joffies posted on Thursday, August 28, 2008

Hi

I have a Parent BusinessBase class which has another child BusinessBase class as a property. If i configure my databinding for this property i get the "Edit level mismatch in CopyState" error.

I have two other properties on the Parent of type BusinessListBase which all work just fine. The only difference being the type of business object the property represents.

I have configured databinding exactly like the samples in the PTracker winforms sample. Could there be any issue with the Undo when have property of BusinessBase type on a Parent BusinessBase class?

Thanks

 

ajj3085 replied on Thursday, August 28, 2008

What version of Csla are you using?  And if it's 3.5 or higher, are you using managed properties or unmanaged properties?

Joffies replied on Thursday, August 28, 2008

I am using 3.5.1 and yes I am using managed properties.

The property on the parent is declared like so..

Private Shared VestingSettingsProperty As PropertyInfo(Of AwardVestingSetting) = RegisterProperty(Of AwardVestingSetting)(GetType(Award), New PropertyInfo(Of AwardVestingSetting)("VestingSettings", "VestingSettings"))

''' <Summary>
''' Gets and sets the VestingSettings value.
''' </Summary>

Public Property VestingSettings() As AwardVestingSetting

Get
Return GetProperty(Of AwardVestingSetting)(VestingSettingsProperty)
End Get

Set(ByVal value As AwardVestingSetting)
SetProperty(
Of AwardVestingSetting)(VestingSettingsProperty, value)
End Set

End Property

 

ajj3085 replied on Thursday, August 28, 2008

I'm not a Vb guy, but I don't think I use the overload of RegisterProperty that takes a type as the first argument.  Maybe take that parameter out and see if that changes things?   Otherwise I'm at a loss... but you may want to post the code were you setting your BindingSources and if you call ApplyEdit CancelEdit, etc.

Joffies replied on Thursday, August 28, 2008

hi again :)

I did tried taking out the overload too but get the same result/error unfortunatly :(

When changing properties for VestingSettings (for example) the parent bindingsource (AwardBindingSource) does not seem to fire either so I am must be setting up something wrong.

My binding setup looks like the following.

Parent (Businessbase)  - AwardBindingSource.datasource = MyLibary.Award

Child 1 (BusinessListbase)   - TransactionsBindingSource.DataSource = AwardBindingSource
                                             TransactionsBindingSource.DataMember = Transactions

Child 2 (BusinessListbase)   - VestingsSettingBindingSource.DataSource = AwardBindingSource
                                             VestingsBindingSource.DataMember = Vestings

Child 3 (Businessbase)   - VestingSettingBindingSource.DataSource = AwardBindingSource
                                        VestingSettingBindingSource.DataMember = VestingSettings

I use the rebind method Rocky uses in the PTracker application and copystate error appears on the _award.CancelEdit line

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

' disable events

Me.AwardBindingSource.RaiseListChangedEvents = False
Me.TransactionsBindingSource.RaiseListChangedEvents = False
Me.VestingsBindingSource.RaiseListChangedEvents = False
Me.VestingSettingsBindingSource.RaiseListChangedEvents = False

Try

' unbind the UI
UnbindBindingSource(Me.VestingSettingsBindingSource, saveObject, False)
UnbindBindingSource(Me.VestingsBindingSource, saveObject, False)
UnbindBindingSource(
Me.TransactionsBindingSource, saveObject, False)
UnbindBindingSource(
Me.AwardBindingSource, saveObject, True)

Me.VestingSettingsBindingSource.DataSource = Me.AwardBindingSource
Me.VestingsBindingSource.DataSource = Me.AwardBindingSource
Me.TransactionsBindingSource.DataSource = Me.AwardBindingSource

' save or cancel changes

If saveObject Then

_award.ApplyEdit()

Try

_award = _award.Save

Catch ex As Csla.DataPortalException

MessageBox.Show(ex.BusinessException.ToString(), _

"Error saving", MessageBoxButtons.OK, _

MessageBoxIcon.Exclamation)

Catch ex As Exception

MessageBox.Show(ex.ToString(), _

"Error Saving", MessageBoxButtons.OK, _

MessageBoxIcon.Exclamation)

End Try

Else

_award.CancelEdit()

End If

Finally

' rebind UI if requested

If rebind Then

BindUI()

End If

' restore events

Me.AwardBindingSource.RaiseListChangedEvents = True
Me.TransactionsBindingSource.RaiseListChangedEvents = True
Me.VestingsBindingSource.RaiseListChangedEvents = True
Me.VestingSettingsBindingSource.RaiseListChangedEvents = True

If rebind Then

' refresh the UI if rebinding

Me.AwardBindingSource.ResetBindings(False)
Me.TransactionsBindingSource.ResetBindings(False)
Me.VestingsBindingSource.ResetBindings(False)
Me.VestingSettingsBindingSource.ResetBindings(False)

End If

End Try

End Sub

Joffies replied on Thursday, August 28, 2008

Ok my bad, i had made a mistake on my Child_Fetch method and passed through the SingleCriteria class of the wrong type...The CopyState error has now gone..but...

Any reason or something I can look at specifically to check why when making changes to to the vestingSettings child object that the AwardBindingSource CurrentItemChanged is not fired at all. As VestingSettings is a child i would expect making changes to properties on the child would automatically fire the parent (AwardBindingSource) bindingsource?

Thanks for any help.

 

 

tmg4340 replied on Thursday, August 28, 2008

IIRC, BusinessBase does not have code to automatically bubble its events to a parent.  BusinessListBase subscribes to the BB events and handles the bubbling for you, and BusinessBase has hooks for child BLB's, but not direct child BB's.

- Scott

Joffies replied on Friday, August 29, 2008

Can anyone else confirm this and possibly provide suggestions on a workaround? Perhaps i need to implement my business object differently? How do other poeple handle situations where there is a one to one mappings?

I cannot see any reason why the BusinessBase parent class shouldnt handle any events fired on the Businessbase child at all unless I am missing something.

Joffies replied on Friday, August 29, 2008

Hello guys!

I am really pulling my hair out on this one...arghhh  I just cannot seem to pinpoint why the Parent BindingSource wil not fire when properties on the child is changed.

The child object (of BusinessBase) behaves exactly as I want it too except for the Undo! :(

Any help or suggestions will be greatly appreciated,

Thanks

ajj3085 replied on Friday, August 29, 2008

This is by design.  It was discovered that doing this causes problems with Data Binding.  for now, you can listen to the ChildChanged event on your root object... but it may not work if you have grandchild objects.

Copyright (c) Marimer LLC