Hi Charlie,
>I was afraid you would say that
How did you know that I was going to answer your question? :p
Allow me to explain the actual problem I am having. The control I am
trying to subclass is a 3rd party Infragistics UltraWinGrid control.
In my subclass, I set the this.DisplayLayout.Override.AllowGroupBy
property to false (just an example), and InitializeComponent looks like
this:
private void InitializeComponent()
{
((System.ComponentModel.ISupportInitialize)(this)) .BeginInit();
this.SuspendLayout();
//
// MyUltraGrid
//
this.DisplayLayout.Override.AllowGroupBy =
Infragistics.Win.DefaultableBoolean.False;
((System.ComponentModel.ISupportInitialize)(this)) .EndInit();
this.ResumeLayout(false);
}
Looks fine so far. When I add this control to a form, the AllowGroupBy =
False line also appears in the InitializeComponent of the form. This is a
problem because if I later decide to change the default value to True, the
grid on the form will still use the False value!
Furthermore, I cannot override any of these properties
(DefaultValueAttribute, Reset..., ShouldSerialize... do not work) since
AllowGroupBy is a property of the Override property which is a property of
DisplayLayout, etc.
At the end of the day, I have about 50 lines of code which is placed into
InitializeComponent for every grid within my application. Furthermore, if
I change any of these defaults in the subclass, I am forced to manually
clean up the dozens of places where this code has been unnecessarily
written.
Is there a solution to this?
If you can live with the designer not showing your default values and if you
are sure that you won't even attempt to override the default values using
the designer, then you may be able to use the following code in your derived
Control to set default values only at runtime when the control is becoming
visible:
protected override void OnCreateControl()
{
if (Site == null || !Site.DesignMode)
{
this.DisplayLayout.Override.AllowGroupBy =
Infragistics.Win.DefaultableBoolean.False;
}
base.OnCreateControl();
}
Since you're not dealing with a FCL control I can't test this myself, but I
assume it will work. Let us know :)
Another solution might be creating a custom designer, but you'll have to
derive from Infragistics designer if you want to retain the expected
design-time behavior, which might not be possible and probably wouldn't be
an easy task anyway. If it comes down to that it's probably not worth your
time, but searching or posting in Infragistics forums might help you to find
a better solution.
--
Dave Sexton