Filter by custom Category

3 posts, 1 answers
  1. Art Kedzierski
    Art Kedzierski avatar
    107 posts
    Member since:
    Nov 2009

    Posted 12 Jul 2012 Link to this post

    I have an object with custom properties. The only properties I wish to display in the property grid are those of category "MyCategory". How would I do that programatically?

    protected string myproperty;
     
    [Category("MyCategory")]
    public string MyProperty{ get; set; }

    I'm already setting the item and populating the RadPropertyGrid; it's the filtering I'm stuck on.

    RadPropertyGrid1.Item = n;
  2. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 13 Jul 2012 Link to this post

    Hi,

    There are several options for you to achieve this. The first of it is to use the Browsable attribute to indicate that the property should not be processed. In case you are using autogenerated PropertyDefinitions, you can cancel the unneeded fields on the AutoGeneratingPropertyDefinition event. The last option is to set these PropertyDefinitions' Visibility to collapsed. However, I would advise you to stick to the former two options, as the latter one is designed to target slightly different scenarios.

    Greetings,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Art Kedzierski
    Art Kedzierski avatar
    107 posts
    Member since:
    Nov 2009

    Posted 17 Jul 2012 Link to this post

    That did it! Here's the code for future reference:

    private void AutoGeneratingPropertyDefinition(object sender, AutoGeneratingPropertyDefinitionEventArgs e)
    {
        AttributeCollection attributes = TypeDescriptor.GetProperties(RadGridView.SelectedItem)[e.PropertyDefinition.DisplayName].Attributes;
     
        CategoryAttribute cat = attributes[typeof(CategoryAttribute)] as CategoryAttribute;
        if (cat.Category != "MyCategory")
        {
            e.PropertyDefinition.Visibility = System.Windows.Visibility.Collapsed;
        }
    }

    Thanks!
    AK
Back to Top