简体   繁体   中英

How to make order of properties in a property grid differ from the order of properties in class declaration

I want to have below class properties to be displayed in PropertyGrid not in the declared order, instead specified attribute? is there such attribute for?

As:

ABC

Thanks.

    public class ApplicationConfiguration
    {
        public ApplicationConfiguration()
        {
        }
        public int A { get; set; }
        public int C { get; set; }
        public int B { get; set; }
}

If you are sending this object from an MVC/WCF application you can use DataMember attribute like below

public class ApplicationConfiguration
    {
        public ApplicationConfiguration()
        {
        }
        [DataMember(Order=1)]
        public int A { get; set; }
        [DataMember(Order = 3)]
        public int C { get; set; }
        [DataMember(Order = 2)]
        public int B { get; set; }
    }

You have many options in deciding how instances of your classes should appear in the property grid. Start off with Design-Time Attributes for Components and go from there.

See Extending Design-Time Support for the big picture. The bottom line is that you can easily cause your properties to display grouped by categories just by adding [Category("categoryName")] attributes. But if you need them to appear in a completely different order from their order of declaration, then you need to create a Designer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM