Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

Is there another methodology for cloning the cells when you inherit?

In fact base.Clone() returns an object of type equals to this.GetType(). A reflection invocation on the default constructor might be done in the DataGridViewTextBox.Clone() method.

It seems that the one methodology for implementing ICloneable would be:

public virtual object Clone()
{
   object clone = this.GetType().GetConstructor( Type.EmptyTypes ).Invoke( null );

   clone.MyData = this.MyData.Clone();
   clone.MyData1 = this.MyData1.Clone();
   ...
   return clone;
}

Then in the inherited class you'd override Clone like this:

public override object Clone()
{
   object clone = base.Clone();
   clone.MyOtherData = this.MyOtherData.Clone();
   return clone;
}



Page view counter