Search code examples
c#winformsclonedatagridviewcolumncustomcolumn

how to copy custom properties when making clone


i am working on a "DataGridView" in C# 3.5, in "winforms" application.

I have a custom column is "MaskTextColumn", i have some custom properties in it like : Mask, "PromptChar" etc.

When i am making clone of "MaskTextColumn" my customer properties is not copied to new object, i want to make clone as it is with custom property value.


Solution

  • You need to override the Clone method in your custom derived class.

    Something like this:

    public override object Clone() 
    {
        var clonedColumn = base.Clone() as CustomColumn;
        clonedColumn.CustomProp = this.CustomProp;
        return clonedColumn;
    }