In Csla 3.0 BindingSource.CancelEdit() is not working

In Csla 3.0 BindingSource.CancelEdit() is not working

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


umesh kanyal posted on Sunday, January 13, 2008

Our Scenerio is like this, we have a collection of CodeValue class that contains Value,start date and end date field. What happens when we click add button, immediately one object of codevalue is added to the CodeValueCollection and is displayed in the grid with blank details. A popup i.e. CodeValueForm gets opened which contains these Value and its start date and end date fields, if we enter anything in these fields and click add it gets added to the CodeValueCollection and reflected in the grid. If we tried to cancel it then the row from the collection doesnot gets removed i.e. it doesnot gets removed from the CodeValueCollection .

It gets removed if we take the reference of csla.dll 2.0 but it doesnot get removed if we take the reference of csla.dll 3.0. That is the same  functionality is working with csla.dll 2.0 and is not working with csla.dll 3.0.

What we analized was that, the BindingSource.CancelEdit() function in OnClosing event in ChildFormBase class is not working in case of Csla.dll 3.0 but in case of csla.dll 2.0 it is working fine.

Structure of our classes are as follows:

1.       CodeValue inherits GBusinessBase
          GBusinessBase inherits Csla.BusinessBase<GBusinessBase>

2.       CodeValueCollection inherits GBusinessListBase<CodeValueCollection, CodeValue>
          GBusinessListBase<CodeValueCollection, CodeValue> inherits Csla.BusinessListBase<T, C>  
          where T : Csla.BusinessBase<GBusinessBase>
           where C : GBusinessBase
          GBusinessBase inherits Csla.BusinessBase<GBusinessBase>


3.      CodeValueListControl inherits ListControlBase2
          ListControlBase2 inherits System.Windows.Forms.UserControl

4.      CodeValueForm inherits ChildFormBase
          ChildFormBase inherits System.Windows.Forms.Form

 CodeValueListControl is a class where we have the CodeValueCollection in the grid

          On click of Add button a new object of CodeValue class is added into CodeValueCollection and displayed in the grid . A popup CodeValueForm is opened with blank details of these fields (Value,start date, end date)

 

Please suggest what is wrong in CancelEdit()

KKoteles replied on Tuesday, January 15, 2008

umesh,

Rocky made some changes in version 3.0 (which you've obviously stumbled upon).  He covers this in Chapter 6 (Data Binding) of his Using CSLA 3.0 handbook.  He explains how the binding is done through the BindingSource control - and as a result, the BeginEdit(), CancelEdit() or ApplyEdit() methods should never be called directly on the business object.

Here are two other threads that talk about this as well:  http://forums.lhotka.net/forums/thread/14583.aspx and http://forums.lhotka.net/forums/permalink/10718/10713/ShowThread.aspx#10713

This issue has "bit" me too.  All my new stuff is fine - it is just the older applications I created with version 2.1.4 that I need to be careful of.

Ken

Copyright (c) Marimer LLC