问题
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