Bug Report CB62649
Visible to All Users

Binding with usercontrol cause design-time problems

created 18 years ago

I get a design time error: "One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes." when I use binding with a UserControl.
I created UserControl with a TextEdit binded with a BindingSource. I put UserControl in form, build project and run. When I come back to the form at design-time, I get an error.
I created an example to demonstrate problem.
Steps to Reproduce:

  1. Create new UserControl
        a. Put TextEdit and BindingSource on UserControl
        b. Create a Class (ex Customer with 1 property "Name")
        c. Set BindingSource.DataSource to Customer class.
        d. Bind TextEdit.EditValue with Customer.Name property
        e. Add public property "Customer" in UserControl to set BindingSource.DataSource
  2. Drop UserControl on form
  3. Set UserControl.Customer property with new instance of Customer
  4. Compile and run.
  5. Close all design-time form
  6. Open Form at design-time (I get an error)
  7. Close Form.
  8. Open UserControl and remove Binding on EditValue
  9. Compile
  10. Open Form as design-time (Form is displayed)
    Actual Results:
    One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes
    Expected Results:
    See form at design-time.
Comments (3)
Stan (DevExpress Support) 18 years ago

    Hello,
    Thank you for the report. I have researched your code and found out that the problem is not directly related to our controls. The cause of the issue is that you are initially passing a null value to the customerBindingSource.DataSource property. Please look at the designer generated code. I have also attached a sample project which demonstrates the same problem without using our suites. The easiest way to resolve this problem is to change your code as shown below:

    C#
    public Customer Customer { get { return (customerBindingSource.DataSource as Customer); } set { if (value == null) { customerBindingSource.Clear(); } else customerBindingSource.DataSource = value; } }

    Please try this solution and inform us of your results.
    Thanks,
    Stan.

    AC AC
    Alexandre Croteau 18 years ago

      All works fine with your solution.
      Thanks for fast response!

      Stan (DevExpress Support) 18 years ago

        You are welcome!
        Thanks,
        Stan.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.