views:

54

answers:

1

hi all! I have this problem, I created my own datagridviewcolumn and I wish add some properties that you can change in designtime editing... here is my code:

private int nMaxLength;
[Description("Fondoscala valore"), Category("Sea")]
public int MaxLength
{
    get { return nMaxLength; }
    set { nMaxLength = value; }
}

and in fact is ok, when you open the column editor, you see this property under the Sea category and you can change, but when you changed it, if you go to the .Designer.cs file, you see the MaxLength value to 0.. no change... what's the problem?? thanks in advance

+1  A: 

The Forms Designer does some internal trickery in order to allow you to change the column type (e.g. from DataGridViewTextBoxColumn to DataGridViewButtonColumn) at design time. As a result of this, the designer relies on your subclass of DataGridViewColumn having a correctly-implemented Clone() method, i.e:

public override object Clone() {
    MyDataGridViewColumn that = (MyDataGridViewColumn)base.Clone();
    that.MaxLength = this.MaxLength;
    return that;
}

If you do not override the Clone() method, the designer will not commit any changes you make to custom property values.

Bradley Smith