Category Ordering In Xceed PropertyGrid

断了今生、忘了曾经 提交于 2020-04-30 05:06:53

问题


I am using PropertyGrid of Xceed to display characteristics of some elements. There are different categories for element like: General, Advanced, Others, Special. Here, I found that the Xceed's propertygrid sorts the category as well as property in alphabetical order. I was able to sort the properties inside the categories by using [PropertyOrder(n)]. I also wanted to sort the categories so, I tried using CategoryOrder like [CategoryOrder("General", 0)] but it shows the following error:

Error 2 Attribute 'CategoryOrder' is not valid on this declaration type. It is only valid on 'class' declarations.

Am I using it wrong? The code provide below is just a sample to show how I am using this.

[Category("General")]
[CategoryOrder("General", 0)]
[DisplayName("XValue")]
[Description("Value of X-Coordinate")]
[ReadOnly(true)]
[PropertyOrder(1)]

[Category("Advanced")]
[CategoryOrder("Advanced", 1)]
[DisplayName("Collision")]
[Description("Collision")]
[ReadOnly(true)]
[PropertyOrder(1)]

[Category("Others")]
[CategoryOrder("Others", 3)]
[DisplayName("Traffic")]
[Description("Traffic at a point")]
[ReadOnly(true)]
[PropertyOrder(1)]

[Category("Special")]
[CategoryOrder("Special", 2)]
[DisplayName("Special cases")]
[Description("Contains the special cases and files")]
[PropertyOrder(1)]

回答1:


Here's a sample on how it should be used:

[CategoryOrder("General", 1)]
[CategoryOrder("Advanced", 2)]
[CategoryOrder("Other", 3)]
public class MyClass
{
    [Category("General")]
    public string Property1 { get; set; }
    [Category("Advanced")]
    public int Property2 { get; set; }
    [Category("Other")]
    public double Property3 { get; set; }
    [Category("General")]
    public string Property4 { get; set; }
    [Category("Advanced")]
    public int Property5 { get; set; }
    [Category("Other")]
    public double Property6 { get; set; }
}



来源:https://stackoverflow.com/questions/36734712/category-ordering-in-xceed-propertygrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!