The blog has moved to a new address. The blog is now located at http://devintelligence.com

Adsense

Monday, February 05, 2007

Propertygrid: How to show and edit "aggregated" property

Sometimes we need to edit  aggregated property - I mean the property that represents object with few properties .The simple way to do this - we can use TypeConverter with ExpandableObjectConverter as shown in the example

 

 

[TypeConverter(typeof(ExpandableObjectConverter))]
public class FullName
{
private string _FirstName;
private string _LastName;


public FullName(string _FirstName, string _LastName)
{
this._FirstName = _FirstName;
this._LastName = _LastName;
}

[DisplayName(
"First Name")]
[Description(
"First name of the person")]
public string FirstName
{
get
{
return _FirstName;
}
set
{
_FirstName
= value;
}
}

[DisplayName(
"Last Name")]
[Description(
"Last name of the person")]
public string LastName
{
get
{
return _LastName;
}
set
{
_LastName
= value;
}
}


///<summary>
///Returns a <see cref="T:System.String"></see>
/// that represents the current <see cref="T:System.Object"></see>.
///</summary>
///
///<returns>
///A <see cref="T:System.String"></see>
/// that represents the current <see cref="T:System.Object"></see>.
///</returns>
///<filterpriority>2</filterpriority>
public override string ToString()
{
return _FirstName + " " + _LastName;
}
}


 


 



[DisplayName("Full Name")]
[Description(
"Full name of the person")]
public FullName FullName
{
get
{
return _FullName;
}
set
{
_FullName
= value;
}
}


Result - the editor for aggregated object



Source( russian )

1 comment:

Anonymous said...

Your code does not work.