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:
- 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 - Drop UserControl on form
- Set UserControl.Customer property with new instance of Customer
- Compile and run.
- Close all design-time form
- Open Form at design-time (I get an error)
- Close Form.
- Open UserControl and remove Binding on EditValue
- Compile
- 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.
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:
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.
All works fine with your solution.
Thanks for fast response!
You are welcome!
Thanks,
Stan.