C# adding collection of custom properties from the property grid at design time

♀尐吖头ヾ 提交于 2019-12-11 07:39:58

问题


I have an issue of not being able to add created columns to the collection of that type.

I have the following property:

public ObservableCollection<BrowseLayoutColumns> _BrowseLayoutColumns = new ObservableCollection<BrowseLayoutColumns>();
    [Category("Design")]
    public ObservableCollection<BrowseLayoutColumns> BrowseLayoutColumns
    {
        get { return _BrowseLayoutColumns; }
        set { _BrowseLayoutColumns = value; }
    } 

BrowseLayoutColumns

[TypeConverter(typeof(BrowseLayoutColumns))]   
public class BrowseLayoutColumns : DataGridViewColumn
{
    #region Properties

    public string ColumnName { get; set; }
    public string BindingField { get; set; }
    #endregion

    public BrowseLayoutColumns()
        : base(new DataGridViewTextBoxCell())
    {
    }

    public override object Clone()
    {
        var copy = base.Clone() as BrowseLayoutColumns;
        copy.ColumnName = ColumnName;
        copy.BindingField = BindingField;            
        return copy;
    }        
}

so on the design time:

after I Press the Ok button.

this is what happens and this is what I wanted to happen

the problem is what the compiler does is :

private void InitializeComponent()
    {
        this.browseLayoutColumns1 = new MyBaseFramework.MyTypeEditors.BrowseLayoutColumns();
        this.SuspendLayout();
        // 
        // browseLayoutColumns1
        // 
        this.browseLayoutColumns1.BindingField = "TEST";
        this.browseLayoutColumns1.ColumnName = "TEST";
        this.browseLayoutColumns1.Name = "browseLayoutColumns1";
        // 
        // BrowseCONTACTS_BASE
        // 
        this.ClientSize = new System.Drawing.Size(606, 447);
        this.Name = "BrowseCONTACTS_BASE";
        this.ResumeLayout(false);
    }

why does not it do the following too?

BrowseLayoutColumns.Add(browseLayoutColumns1);

what am I missing? any help would be very beneficial! thanks in advance

来源:https://stackoverflow.com/questions/45836304/c-sharp-adding-collection-of-custom-properties-from-the-property-grid-at-design

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!