Skip to content

Customize the WinForms Property Grid to display specific properties of an object.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/winforms-propertygrid-filter-object-properties

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Property Grid - Filter object properties (CustomPropertyDescriptors event)

This example handles the Property Grid's CustomPropertyDescriptors event to display properties based on a condition.

The example displays Dock, Size, and Location properties at the root. For the Size property, the example displays the Height property.

void propertyGridControl1_CustomPropertyDescriptors(object sender, CustomPropertyDescriptorsEventArgs e) {
    // Specifies properties to display at the root level.
    if(e.Context.PropertyDescriptor == null) {
        PropertyDescriptorCollection filteredCollection = new PropertyDescriptorCollection(null);
        AddIfPropertyExist(e.Properties, filteredCollection, "Dock");
        AddIfPropertyExist(e.Properties, filteredCollection, "Size");
        AddIfPropertyExist(e.Properties, filteredCollection, "Location");
        AddIfPropertyExist(e.Properties, filteredCollection, "NonexistentProperty");
        e.Properties = filteredCollection;
    }
    // Specifies nested properties for the Size property.
    if(e.Context.PropertyDescriptor != null && e.Context.PropertyDescriptor.Name == "Size") {
        PropertyDescriptorCollection filteredCollection = new PropertyDescriptorCollection(null);
        AddIfPropertyExist(e.Properties, filteredCollection, "Height");
        e.Properties = filteredCollection;
    }
}

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)