Tuesday, August 25, 2009

Add Custom Property into DataGridViewTextBoxColumn

public class CustomDataGridViewTextBoxColumn : DataGridViewTextBoxColumn
{
private bool _displayContextMenu = false;
public bool DisplayContextMenu
{
set { _displayContextMenu = value; }
get { return _displayContextMenu ; }
}

public override object Clone()
{
CustomDataGridViewTextBoxColumn myCol = (CustomDataGridViewTextBoxColumn)base.Clone();
myCol.DisplayContextMenu = _displayContextMenu ;
return myCol;
}
}

Note: When you derive from DataGridViewTextBoxColumn and add new properties to the derived class, be sure to override the clone method to copy the new properties during cloning operations. You should also call the base class's clone method so that the properties of the base class are copied to the new cell.

No comments:

Post a Comment