Custom property won't save when changed in property window

前端 未结 1 975
青春惊慌失措
青春惊慌失措 2021-01-21 01:11

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.

1条回答
  •  温柔的废话
    2021-01-21 01:40

    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;
      }
    }
    

    See Custom properties on overridden DataViewColumn do not save

    0 讨论(0)
提交回复
热议问题