WinForms PropertyGrid具有空和非空类别

时间:2010-12-01 07:33:49

标签: c# winforms propertygrid

有没有办法自定义Winforms PropertyGrid,如果它需要在顶部显示一个没有类别的元素(完整行)和几个包含内部元素的类别?

1 个答案:

答案 0 :(得分:2)

using System;
using System.ComponentModel;
using System.Windows.Forms;
static class Program {
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        using (var form = new Form {
            Controls = {
                new PropertyGrid { Dock = DockStyle.Fill,
                    SelectedObject = new Test {
                        Foo = "one element without category",
                        Bar = "several categories",
                        Blip = "with elements",
                        Blap = "inside",
                        Blop = "below"
                    }}}}) {
            Application.Run(form);
        }
    }
}
class Test {
    [Category(" ")] public string Foo { get; set; }

    [Category("x")] public string Bar{ get; set; }
    [Category("x")] public string Blip { get; set; }

    [Category("y")] public string Blap { get; set; }
    [Category("y")] public string Blop { get; set; }
}