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;
}
}
(you will be redirected to DevExpress.com to submit your response)