简体   繁体   English

添加datagridviewcolumn属性设计时

[英]add datagridviewcolumn property designtime

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

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?? 并且实际上是可以的,当您打开列编辑器时,您会在Sea类别下看到此属性,并且可以更改,但是当您更改它时,如果转到.Designer.cs文件,则会看到MaxLength值为0 ..没有变化...是什么问题?? thanks in advance 提前致谢

The Forms Designer does some internal trickery in order to allow you to change the column type (eg from DataGridViewTextBoxColumn to DataGridViewButtonColumn ) at design time. 表单设计器做了一些内部技巧,以便允许您在设计时更改列类型(例如,从DataGridViewTextBoxColumn更改为DataGridViewButtonColumn )。 As a result of this, the designer relies on your subclass of DataGridViewColumn having a correctly-implemented Clone() method, ie: 结果,设计器依赖于您的DataGridViewColumn子类,该子类具有正确实现的Clone()方法,即:

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. 如果不重写Clone()方法,则设计器将不会提交对自定义属性值所做的任何更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM