Error on windows form designer

Posts   
 
    
wexa
User
Posts: 38
Joined: 27-Jul-2007
# Posted on: 04-Jul-2008 08:55:06   

Hello, I am using windows forms, and I created a custom control that searches for an entity, I am getting an error on the forms designer when I add this control, the application runs OK but every form that I add this control, is having the same problem

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.

The ConnectionString property has not been initialized. Hide

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

I have attached the control That I am using.

Regards

Attachments
Filename File size Added on Approval
control.rar 3,403 04-Jul-2008 08:55.54 Approved
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Jul-2008 11:34:37   

The ConnectionString property has not been initialized, means you are triggering lazy loading in the constructor. You should check whether the control is in design mode or not. You can do that (if I'm not mistaken) by checking the controls' 'Site' property, if that's non-null, the control is in design mode.

wexa
User
Posts: 38
Joined: 27-Jul-2007
# Posted on: 05-Jul-2008 20:14:42   

Thank you for the reply Walaa, I am using windows forms, but cant find the SITE property for my control, I have tryied with different options but no one works.

The form works ok at runtime but in design time is my problem because I cant see the designer.

Is there another thing I should check?? Or probably have not undesrtood what you recomended.

Thank you for your help

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Jul-2008 21:19:07   

Hi wexa,

You are triggering some lazy stuff at ctor, this causes the designer try to run that code when you put the control at designer. I would try these options:

A. Sorround the offending code at constructor by this:

if( !DesignMode ) 
{
     ...
}

B. Move the offending code to the Load event.

David Elizondo | LLBLGen Support Team
wexa
User
Posts: 38
Joined: 27-Jul-2007
# Posted on: 06-Jul-2008 22:04:37   

Thank you very much, I was trying to access a property of an entity trough a control and there was the error.

I used the Site.DesignMode property that you recomended, I found this that may be for help for others in my situation

http://bytes.com/forum/thread107824.html and http://groups.google.se/group/microsoft.public.dotnet.framework.windowsforms.controls/msg/e2b16206a7d45eeb

The code used on the public property of the control that works is:


public int vehicleId
        {
            get
            {
                return auxVehicleId;
            }
            set
            {
                if (!Site.DesignMode)
                {
                    auxVehicleId = value;
                    if (auxVehicle == null)
                    {
                        auxVehicle = VehiculeManager.getBy(value);
                    }
                }
                
            }
        }

Regards

zee
User
Posts: 35
Joined: 24-Jul-2008
# Posted on: 29-Jul-2008 21:58:50   

btw., here is a suggestion... i have done this in some applications where i have created containers/controls that i would like to display "something" while i play around...

in your else clause you could call the function with a default value...

if (!Site.DesignMode) { auxVehicleId = value; if (auxVehicle == null) { auxVehicle = VehiculeManager.getBy(value); } } else { auxVehicle = VehiculeManager.getBy(1); }