开发者

Multiple Categories in .NET PropertyGrid are not visible with Attributes

开发者 https://www.devze.com 2023-02-07 07:01 出处:网络
I have a PropertyGrid with 2 Categories: \"Customer Test 1\" and \"Customer Test 2\" If I have only ONE CategoryAttribute in the BrowseableAttributes ONE Category is shown.

I have a PropertyGrid with 2 Categories: "Customer Test 1" and "Customer Test 2"

If I have only ONE CategoryAttribute in the BrowseableAttributes ONE Category is shown. If I have BOTH/TWO CategoryAttribute`s in the BrowseableAttributes NONE category is shown.

Why that?

public class Customer
    {
        [DisplayName("first name...:")]
        [Category("Customer Test 1")]
        public string FirstName { get; set; }

        [DisplayName("number...")]
        [Category("Customer Test 1")]
        public int Number { get; set; }

        [DisplayName("wage...:")]
        [Category("Customer Test 2")]
        public int Wage { get; set; }

        [DisplayName("description...:")]
        [Category("Customer Test 1")]
        public string  Desc { get; set; }

        [DisplayName("shit...:")]
        [Category("Customer Test 1")]
        public string Nonsens { g开发者_Go百科et; set; }      
    }

    public Form1()
            {
                InitializeComponent();

                Attribute[] attributes = new Attribute[]{ new CategoryAttribute("Customer Test 1"), new CategoryAttribute("Customer Test 2") };
                propertyGrid1.BrowsableAttributes = new AttributeCollection(attributes);

                propertyGrid1.PropertySort = PropertySort.Categorized;
                propertyGrid1.ToolbarVisible = true;
                propertyGrid1.SelectedObject = new Customer() { FirstName = "Bernd", Number = 100, Desc = 

"steine", Wage = 3333, Nonsens = "crap" };
        }


Are you sure that if you assign multiple attributes to BrowsableAttributes, properties need to have only 1 matching attribute and not ALL of them?

In other words, BrowsableAttributes might act as a filter using and AND operator on the attributes instead of an OR. But I have to admit that I have not tried this myself.

0

精彩评论

暂无评论...
验证码 换一张
取 消