all groups > dotnet windows forms designtime > august 2005 >
You're in the

dotnet windows forms designtime

group:

Visual designer not setting values of custom control properties



Visual designer not setting values of custom control properties Nadav Popplewell
8/3/2005 2:28:02 AM
dotnet windows forms designtime: I've got a strange problem with a custom control of mine.

The control got several properties, all of which a simple values (i.e. int
or string).

When I put the control on a form the code in the form InitializeCompoment()
is :

this.gridLayout21 = new BacSoft.Controls.GridLayout2();
((System.ComponentModel.ISupportInitialize)(this.gridLayout21)).BeginInit();
this.SuspendLayout();
//
// gridLayout21
//
this.gridLayout21.CellCaching = true;
this.gridLayout21.ColResizeInfo = "";
this.gridLayout21.Columns = 2;
this.gridLayout21.InnerPadding = 0;
..
..
..

It works perfectly when I run the application. All the properties are set
correctly.
The value of the column property is serialized to code properly,
but for some reason, when showing the form in the designer
the this.gridLayout.Columns Property is NOT set.
the other properties (CellCaching,ColResizeInfo,InnerPadding ) are set, but
Columns is not set.

I've tried debugging it (but openning another devenv and attaching to the
first devenv instance), and putting breakpoint in all the properties' set
accessors.
When openning the form in the debugged devenv The debugger stops on th
breakpoints in the CellCaching,ColResizeInfo,InnerPadding properties, but NOT
in the Columns property.

All my properties are defined with just the Browsable property:

[Browsable(true)]
public int Columns {
get { return _cols; }
set {
if (value<0) {
_cols=0;
} else {
_cols=value;
}
Arrange(true);
}
}

[Browsable(true)]
public int InnerPadding {
get { return _innerPadding; }
set {
bool ar=(_innerPadding!=value);
_innerPadding=value;
if (ar)
Arrange(false);
}
}

Can anybody think of anyway to fix this?

Thanks,
Nadav
RE: Visual designer not setting values of custom control properties Nadav Popplewell
8/3/2005 3:47:04 AM
OK, I' ve found the problem.

I had an interface:
public interface IGridControl {
int Rows { get; }
int Columns { get; }
}

which my Component implmented.

Apparently if the property implments a property of an interface the designer
fails to find this property (or does not recognize it as a property that
needs to be set).

When I changed the interface to
public interface IGridControl {
int getRows();
int getColumns();
}

then the designer initialized my component properties properly.

Is this behavior by design?

Is it possible that the designer got confused because the properties in the
interface were readonly ( int Rows { get; } ) but the properties of the
Component were Read/Write ( int Rows { get {..} set {..} } ) ?

Nadav

AddThis Social Bookmark Button