Reputation: 991
I have a datagridview in my form. This datagridview has some columns. There are some custom columns (I have created custom datagridview cells). These custom cells have some properties that I want to do visible from datagridview's columns editor in design time in order to set them. So in design time, I open datagridview's columns editor, and I create a column of the custom datagridview cell. Then, I set some custom properties and I close datagridview's olumns editor. When I open the datagridview's columns editor, the values that I set previously for those custom properties are not reflected, it seems like they were not saved once datagridview's columns editor was closed. So... why? why the values for the custom properties are not saved? What Am i doing wrong?
Furthermore, I cannot leave as empty these custom properties because an exception I raised once form is loaded (object reference not set as a instance of an object).
I highly appreciate if someone could help me.
Upvotes: 4
Views: 1511
Reputation: 2557
I ran into this identical issue. After searching, I found some feedback on a microsoft site that said I had to implement iCloneable
in my datagridviewtextboxcolumn
derivation.
You can find the article here and the relevant section:
In some rare cases, the column type may want to expose a property that has no equivalent property at the cell level. Examples of that are DataGridViewLinkColumn.Text and DataGridViewImageColumn.Image. In those cases, the column class needs to override the Clone method to copy over that property.
My column added four extra properties, and here's my icloneable function:
//Override this method to set the custom properties.
public override object Clone()
{
var col = base.Clone() as BauerDataGridViewTextBoxColumn;
col.ShowBorder = this.ShowBorder;
col.BorderColor = this.BorderColor;
col.ColumnChooserIsOptional = this.ColumnChooserIsOptional;
col.ColumnChooserColumnLabel = this.ColumnChooserColumnLabel;
return col;
}
Upvotes: 4