garethv

garethv

  • NA
  • 1
  • 0

Nested Component and ISupportInitialize

Nov 18 2005 1:11 AM

Hi

I have  a SubComponent which implements ISupportInitialize which is nested in a ParentComponent. The ParentComponent has a property (with DesignerSerializationVisibility.Content attribute) which returns the instance of sub component.

*************************Source********************************

public class ParentComponent : Component{
SubComponent _subComponent;
public ParentComponent() {
_subComponent =
new SubComponent();}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public SubComponent SubComponent
{
get { return _subComponent; } }
}

[System.ComponentModel.ToolboxItem(false)]
public class SubComponent : Component, ISupportInitialize{
string _name;
public SubComponent() { }
public string Name
{
get { return _name; }set { _name = value; }}
public void BeginInit() {}
public void EndInit() {}
}

**************************************************************
When I place the component on a form the code generated is

private
void InitializeComponent()
{t
his
.parentComponent1 = new ParentComponent();
((System.ComponentModel.ISupportInitialize)(this.parentComponent1.SubComponent)).BeginInit();

My problem is if I now change the name of the ParentComponent to "ParentNewName" in the properties window then the SubComponent name does not refresh and I end up with

private void InitializeComponent()
{
this.ParentNewName = new SimpleComponent.ParentComponent();
((System.ComponentModel.ISupportInitialize)(this.parentComponent1.SubComponent)).BeginInit();
                                                                          ^^^^^^^^^^^^

Any Ideas on how to get the Generated Code to refresh this line as well?

Thanks in advance