在属性窗口自定义属性不会改变的时候保存 [英] Custom property won't save when changed in property window
问题描述
我已经为DataGridView中自定义列,原因是我想要的属性(类型)添加到列。
我右键单击在DataGridView并选择编辑列...。然后,当我选择这是我的自定义字段类型,我能够编辑属性,但如果我类C确定修改完成后,然后进入编辑列...再次,我分配给我的财产值的列。走了
I've created a custom column for DataGridView, and the reason is that I want to add a property (type) to a column. I right click the DataGridView and select "Edit columns...". Then when I select the column that is my custom column type I'm able to edit the property, but if I clike "OK" after editing and then go to "Edit columns..." again the value that I assigned to my property is gone.
下面是我的代码:
public class CustomColumn : DataGridViewColumn
{
[DisplayName("Type")]
[Category("Custom Property")]
public String type { get; set; }
public CustomColumn()
: base(new DataGridViewTextBoxCell())
{
}
}
和属性窗口的图像:
谁能告诉我,我做错了什么,或我需要补充,这样当我改变在属性窗口中的值,该值是分配给属性?
Can someone tell me what I'm doing wrong, or what I need to add so that when I change the value in the property window, that value is assigned to the property?
推荐答案
我认为你需要重写克隆()
方法,以便该工作:
I think you need to override the Clone()
method in order for that to work:
public class CustomColumn : DataGridViewColumn {
public CustomColumn()
: base(new DataGridViewTextBoxCell()) {
}
[DisplayName("Type")]
[Category("Custom Property")]
public String type { get; set; }
public override object Clone() {
CustomColumn copy = base.Clone() as CustomColumn;
copy.type = type;
return copy;
}
}
这篇关于在属性窗口自定义属性不会改变的时候保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!