ghiboz
ghiboz

Reputation: 8003

custom property DataGridViewTextBoxColumn not saved

I need to add a string property to a DataGridViewTextBoxColumn: to do this I've created my custom column:

public class MhsDataGridViewTextBoxColumn : DataGridViewTextBoxColumn
{
    public string TableName { get; set; }

    public MhsDataGridViewTextBoxColumn()
    {
        this.CellTemplate = new DataGridViewTextBoxCell();
    }
}

and in the columns editor appears correctly:

enter image description here

but if I press ok and save the column properties, the new property is not saved and each time I open the columns editor the TableName property is blank..

is there a simple way to store the custom properties?

thanks

Upvotes: 2

Views: 273

Answers (1)

LarsTech
LarsTech

Reputation: 81610

I believe you are required to override the Clone function in order for that to work:

public override object Clone() {
  var column = base.Clone() as MhsDataGridViewTextBoxColumn;
  if (column != null) {
    column.TableName = this.TableName;
  }
  return column;
}

Upvotes: 6

Related Questions