This is a migrated thread and some comments may be shown as answers.

Filter by custom Category

2 Answers 57 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Art Kedzierski
Top achievements
Rank 2
Art Kedzierski asked on 12 Jul 2012, 07:33 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Ivanov
Telerik team
answered on 13 Jul 2012, 08:10 AM
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 >>
0
Art Kedzierski
Top achievements
Rank 2
answered on 17 Jul 2012, 02:47 PM
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
Tags
PropertyGrid
Asked by
Art Kedzierski
Top achievements
Rank 2
Answers by
Ivan Ivanov
Telerik team
Art Kedzierski
Top achievements
Rank 2
Share this question
or