Hi Peter,
Thank you for posting in the community!
Based on my understanding, you want to implement an extended datagrid in
C#, and you want to initialize your extended datagrid with an existed
normal datagrid instance.
==========================================
In your description "copy a parent class instance's all datas to a
child's", what exactly does "all data" mean? Does it mean "Shadow Copy" or
"Deep Copy"?
To see the difference between "Shadow Copy" and "Deep Copy", please refer
to "Remarks" section in below link:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemobjectclassmemberwiseclonetopic.asp
Based on your code snippet, I think you want to implement "Shadow
Copy"(Because you use MemberwiseClone method)
Because MemberwiseClone is a protected member of object class, you can not
call it outside of this class or its child class. (That's why the error
message generates)
Just as Daniel said, to do clone in .Net, you may implement the ICloneable
interface, this interface only takes one method "Clone", which you can do
your copy implement. Normally, to do Shadow Copy, you can just call the
object.MemberwiseClone in the interface's implement.
In "ICloneable Interface" below, you will see that, DataGrid class does not
implement ICloneable interface, so you must implement this interface
yourself:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemicloneableclasstopic.asp
As a whole, you should do like this:
public class MyDataGrid : ICloneable, DataGrid
{
public object Clone()
{
return this.MemberwiseClone();
}
}
public class extendeddatagrid: DataGrid
{
public extendeddatagrid(MyDataGrid obj)
{
this=obj.Clone() as DataGrid;
}
}
Note: in the constructor parameter, you must use the class inherited from
DataGrid, which may not meet your need(You want to take the Normal DataGrid
as parameter), if you really want to use normal DataGrid as parameter, you
must do the Shadow Copy yourself in the constructor, which may be
troublesome.
=================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.