PropertyGrid 显示自定义类属性

很多人不清楚PropertyGrid 怎么显示自定义类属性,这里写个小例子供参考



    class A
    {
        string m_Name;
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }

        }

        int m_ID;
        public int ID
        {
            get { return m_ID; }
            set { m_ID = value; }
        }
    }

    class B
    {

        A m_A;
        [TypeConverter(typeof(ExpandableObjectConverter))]   //使用转换器
        public A A
        {
            get { return m_A; }
            set { m_A = value; }
        }

    }


            B b = new B();
            b.A = new A();
            m_PropertyGrid1.SelectedObject = b;
            m_PropertyGrid1.ExpandAllGridItems();

你可能感兴趣的:(.NET,小知识拾遗)