C
Christian Weinert
Hello,
I currently fight with a problem during the derivative of WinForm controls.
In Visual Studio I created a new User Control. This control is derived from
the DataGridView of the System.Windows.Forms namespace. I want to use this
control as a template for futher controls. Within this control i want to set
some property values to be pre-defined for further derived controls.
My base class looks like this:
public partial class BaseDataGrid : System.Windows.Forms.DataGridView
{
private bool _Enabled;
public BaseDataGrid() : base()
{
InitializeComponent();
this.Enabled = false;
}
[DefaultValue(false)]
public new bool Enabled
{
get
{
return this._Enabled;
}
set
{
this._Enabled = value;
}
}
}
For testing this control I created a WinForm and put it on the form. Looking
at the property window shows the Enabled-Property as set to "true". and not
as expected to "false". The entry "true" is bold, so the Designer recognized
that the default value for this property is "false".
Further, I derived a new User Control from my BaseDataGridView control, put
it on my form. As the BaseDataGridView the property window shows the
Enabled-Property as set to "true".
It seems that the Designer uses the Property-Value of the next-higher level
control in a control hierarchy as the default value for this property. But,
for pre-defining the property it uses the property default value of the
highest class in the object hierarchy.
My second approch was not to "override" the Enabled-Property. I only set the
Enabled-property derived from the DataGridView to "false".
My BaseDataGrid-class now looks like this:
public partial class BaseDataGrid : System.Windows.Forms.DataGridView
{
public BaseDataGrid() : base()
{
this.Enabled = false;
}
}
One again, putting this control on a WinForm is suprising me. Within the
property window the Enabled-property is set to false. Everything seems to be
fine. But when changing it to "true" there will be not code is written into
the InitializeComponent-method of the form. When starting the form the
control will be disabled. Debugging the InitializeComponent-method shows that
the control has its Enabled-property set to "false".
Part of the InitializeComponent-method when putting the control on the form:
this.baseDataGrid1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.baseDataGrid1.Enabled = false;
this.baseDataGrid1.Location = new System.Drawing.Point(358, 88);
this.baseDataGrid1.Name = "baseDataGrid1";
this.baseDataGrid1.Size = new System.Drawing.Size(240, 150);
this.baseDataGrid1.TabIndex = 0;
Part of the InitializeComponent-method after setting the property to true:
this.baseDataGrid1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.baseDataGrid1.Location = new System.Drawing.Point(358, 88);
this.baseDataGrid1.Name = "baseDataGrid1";
this.baseDataGrid1.Size = new System.Drawing.Size(240, 150);
this.baseDataGrid1.TabIndex = 0;
Hope, anyone of you has an idea how to solve this problem.
Thanks and best regrads
Chris
I currently fight with a problem during the derivative of WinForm controls.
In Visual Studio I created a new User Control. This control is derived from
the DataGridView of the System.Windows.Forms namespace. I want to use this
control as a template for futher controls. Within this control i want to set
some property values to be pre-defined for further derived controls.
My base class looks like this:
public partial class BaseDataGrid : System.Windows.Forms.DataGridView
{
private bool _Enabled;
public BaseDataGrid() : base()
{
InitializeComponent();
this.Enabled = false;
}
[DefaultValue(false)]
public new bool Enabled
{
get
{
return this._Enabled;
}
set
{
this._Enabled = value;
}
}
}
For testing this control I created a WinForm and put it on the form. Looking
at the property window shows the Enabled-Property as set to "true". and not
as expected to "false". The entry "true" is bold, so the Designer recognized
that the default value for this property is "false".
Further, I derived a new User Control from my BaseDataGridView control, put
it on my form. As the BaseDataGridView the property window shows the
Enabled-Property as set to "true".
It seems that the Designer uses the Property-Value of the next-higher level
control in a control hierarchy as the default value for this property. But,
for pre-defining the property it uses the property default value of the
highest class in the object hierarchy.
My second approch was not to "override" the Enabled-Property. I only set the
Enabled-property derived from the DataGridView to "false".
My BaseDataGrid-class now looks like this:
public partial class BaseDataGrid : System.Windows.Forms.DataGridView
{
public BaseDataGrid() : base()
{
this.Enabled = false;
}
}
One again, putting this control on a WinForm is suprising me. Within the
property window the Enabled-property is set to false. Everything seems to be
fine. But when changing it to "true" there will be not code is written into
the InitializeComponent-method of the form. When starting the form the
control will be disabled. Debugging the InitializeComponent-method shows that
the control has its Enabled-property set to "false".
Part of the InitializeComponent-method when putting the control on the form:
this.baseDataGrid1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.baseDataGrid1.Enabled = false;
this.baseDataGrid1.Location = new System.Drawing.Point(358, 88);
this.baseDataGrid1.Name = "baseDataGrid1";
this.baseDataGrid1.Size = new System.Drawing.Size(240, 150);
this.baseDataGrid1.TabIndex = 0;
Part of the InitializeComponent-method after setting the property to true:
this.baseDataGrid1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.baseDataGrid1.Location = new System.Drawing.Point(358, 88);
this.baseDataGrid1.Name = "baseDataGrid1";
this.baseDataGrid1.Size = new System.Drawing.Size(240, 150);
this.baseDataGrid1.TabIndex = 0;
Hope, anyone of you has an idea how to solve this problem.
Thanks and best regrads
Chris