3

我有这个问题,我创建了自己的datagridviewcolumn,我希望添加一些可以在设计时编辑中更改的属性......这是我的代码:

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

其实没问题,当你打开列编辑器时,你在Sea类别下看到这个属性,你可以改变它,但是当你改变它时,如果你去.Designer.cs文件,你看到MaxLength值为0 ..没有变化...有什么问题??提前致谢

4

1 回答 1

8

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.

于 2010-09-16T15:04:40.163 回答