Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 2.82 KB

File metadata and controls

44 lines (35 loc) · 2.82 KB

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)