1. 创建PropertyGrid控件对象
2. 创建填充类:
CategoryAttribute字段上方属性,用来进行分组
DescriptionAttribute字段上方属性,用来进行解释说明
public class Xin
{
[CategoryAttribute("唯一标识"), DescriptionAttribute("表主键")]
public int id { set; get; }
public string name { set; get; }
public int age { set; get; }
public string sex { set; get; }
public override string ToString()
{
return id + name + age + sex;
}
}
3. 用类对象填充控件:this.propertyGrid.SelectedObject = xin;
最终效果: