CloseWinPart error

CloseWinPart error

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


nbx posted on Thursday, August 13, 2009

Building first sample application using CSLA and having an exception thrown when closing custom user control, I am using same approach as implemented in ProjectTracker  (C# 2005), line which

is having problem is in CloseWinPart method,

MainPanel.Controls.Remove(part)

this is the exception:

"Cannot bind to the property or column EmpName on the DataSource.
Parameter name: dataMember "

my  UserControl has proper binding, and everything works fine until I close the control and getting above exception.

Any help / direction would be appreciated. Thanks

 

 

triplea replied on Friday, August 14, 2009

Could you post a full example (just your user control and a host form) recreating the problem? I have seen this before but cannot recall how I ended up fixing this.

JonnyBee replied on Friday, August 14, 2009

Hi,

With Windows Forms you should alvays disconnect the BindingSources before you dispose of controls. There is no way you can control the sequence of dispose in Forms/UserControls - so I always create a method called
        public void UnbindUI(bool cancel) {
         }
in my forms/controls.

And you MUST disconnect BindingSources in correct order (reverse order of how you setup databinding).

What happens is f.ex that:
    a ComboBox has 2 databindings
          - one for the list of items
          - one for SelectedValue or SelectedText
    and if the ComboBox loses the list of values while databinding for SelectedXYZ is still active it will actually write the defaultvalue for the datatype of SelectedXYZ to your BusinessObject.

/jonnybee

nbx replied on Tuesday, August 18, 2009

Thanks for your suggestions ...

In my case I do proper unbinding, and the sample case is very simple - I have a control with two labels bound to binding source, calling CSLA unbind method, verified that binding source set to null, and still getting this error on trying to remove control from the panel :
Panel1.Controls.Remove(part);

what's weird is that error message states that it can't bind to the object, but during remove method call ?

any chance it is related to CSLA's bindingSourceRefresh ? I haven't added it to my project, may be I need it.

thanks again.

JonnyBee replied on Tuesday, August 18, 2009

Hi,

How do you unbind from the DataSource - and another key information her is that the error makes reference to the field EmpName. Is this one of the fields that are bound to your custom control?

To me - it seems the problem is that there is still active databindings in your panel/controls.

/jonnybee



Copyright (c) Marimer LLC