日期:2014-05-17 浏览次数:21375 次
private void Form_Load(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = new Person();
}
[TypeConverter(typeof(PropertySorter))]
[DefaultProperty("Name")]
public class Person
{
protected const string PERSONAL_CAT = "Personal Details";
private string _name = "Bob";
private DateTime _birthday = new DateTime(1975,1,1);
[Category(PERSONAL_CAT), PropertyOrder(10)]
public string Name
{
get {return _name;}
set {_name = value;}
}
[Category(PERSONAL_CAT), PropertyOrder(11)]
public DateTime Birthday
{
get {return _birthday;}
set {_birthday = value;}
}
[Category(PERSONAL_CAT), PropertyOrder(12)]
public int Age
{
get
{
TimeSpan age = DateTime.Now - _birthday;
return (int)age.TotalDays / 365;
}
}
}
//
// (C) Paul Tingey 2004
//
using System;
using System.Collections;
using System.ComponentModel;
namespace OrderedPropertyGrid
{
public class PropertySorter : ExpandableObjectConverter
{
#region Methods
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
//
// This override returns a list of properties in order
//
PropertyDescriptorColl