Notifying the Collection Editor of changes
C#, Component Development, Win Forms October 12th, 2006When you are building your own collections of objects it is common to use an overridden ToString implementation to display some property of your object in the collection editor instead of the full class name which is the default.
For example, when developing a Column collection, I override the ToString() to return the Columns caption. However, when the caption property of my column is updated in the standard collection editor, the respective item in the list of items in the collection editor is not updated.
The collection editor can be notified to refresh it’s properties and therefore the list by adding a RefreshProperties attribute to the property that causes the required change.
e.g.
public class TreeColumn
{
private String _Caption;
[RefreshProperties(RefreshProperties.All)]
[Browsable(true)]
[Description("The Caption for the column")]
public String Caption
{
get { return _Caption; }
set { _Caption = value; }
}
public override string ToString()
{
if (!String.IsNullOrEmpty(_Caption))
return _Caption;
return base.ToString();
}
}
Recent Comments