Unbinding BindingSource and ComboBoxes?

Unbinding BindingSource and ComboBoxes?

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


Phlar posted on Wednesday, March 24, 2010

Good Day All,

I have encountered a small error in the EditLevels of our application.  When the Form is loaded, the EditLevels between the parent and child are correct (2 True, 1 False) after the BindUI is completed.

After a change is made to the parent and saved, when the BindUI is completed (after the RebindUI is called) our edit levels are (1 False, 1 False).

The details are saved correctly to the database but a subsequent modification and save will produce an error.

I am wondering whether not unbinding the combo boxes from their NVL is causing the problem or not?

Phlar replied on Wednesday, March 24, 2010

After some additional changes, I've managed to eliminate the error message I was encountering with the EditLevels still at the root object of 1 False.

Can anyone forsee a problem with this?

Phlar replied on Friday, March 26, 2010

Still stuck at this roadblock.  I just realized I should have provided more information.  We have a WinForm containing a panel with a treeview in Panel 1.  When the form is loaded we retrieve our object (Root, Children, GrandChildren, etc....) and store it in a local varible only at this point.  The treeview is constructed based on details in the CSLA object we have retrieved.  When a node is selected we dynamically create a WinPart control passing the object selected and execute the following code in the WinPart control:

Constructor

 - assign the object to a local variable

Load Event:

- Initialize the this.CurrentPrincipalChanged event

- Initialize the object's PropertyChanged event

- Call the BindUI() and ApplyAuthorizationRules() methods

BindUI:

- Invoke the BeginEdit() method of the root object in the Parent Form (i.e. WinForm)

- Assign the BindingSource object on the control with the root object from the Parent Form

- Assign the BindingSource for the selected child (or GrandChild) with the local variable assigned in the constructor

ReBindUI:

- Disable the events by setting the BindingSource's  RaiseListChangedEvents to false

- Disable the select objects PropertyChanged event (-= Event(PropertyChanged))

- Called the UnbindBindingSource method for the two BindingSources and passing saveObject and true parameters to both

- Invoked ApplyEdit on the Parent Form's root object

- Invoked Save on the Parent Form's root object

- Re-established the object's PropertyChanged event

 

 - Invoked the BindUI() event

- Restored events by setting the BindingSource's  RaiseListChangedEvents to true

- Reset the bindings on the BindingSources (ResetBindings).

Can anyone lend a helping hand before I completely loose my mind.  It will be much appreciated.

Copyright (c) Marimer LLC