Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How to Hide Entire Category in a PropertyGrid
 

How to Hide Entire Category in a PropertyGrid

Hi Folks,

I would like to know if there is a way of Hiding entire category from a PropertyGrid (PG)

I have been using the Browsable(False) attribute on property that I need want to be displayed on the PG. Then when all properties belonging to a perticular category have been browsabled-false the category automatically dispeared.

However, I still have the a category that are still present and that is the Design category.

It contains the Name and Locked properties, but I would like to remove them too.

Is anyone knows how to get around doing that?

Thanks

Seve

Severin123  Thursday, November 23, 2006 12:36 PM
Moved to Windows Forms Designer forum.
nobugz  Thursday, November 23, 2006 12:53 PM
you can try implementing ICustomTypeDescriptor and override the PropertyDescriptorCollection being queried by the designer for the properties. I believe these Design Categorized properties are added on the fly by the designer so this might not work but you can try it.
joeycalisay  Friday, November 24, 2006 12:09 PM

I have solvented this issue using a TypeConverter in my components. The following line implement a custom TypeConverter for a component:

[TypeConverter(typeof (MyCustomTypeConverter))]

The class called 'MyCustomTypeConverter' must inherits from the ExpandableObjectConverter class.

for example:

public class MyCustomTypeConverter: ExpandableObjectConverter

In this class, you must implement the use of Properties Attributes objects. Using properties attributes, you can to define an attribute or category called 'MyFilteredProperties' and looking for this to return  in a PropertyDescriptor collection.

 

See more details at:

http://www.codeproject.com/csharp/wdzpropertygridutils.asp
10x to zeeuw for the article.

If you use the supplied code, you must to change some lines for hide unwanted properties.

At the public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) function, you must to add some like this:

....
.... previous code ommited

// For each property use a property descriptor of
// our own that has custom behaviour.

ArrayList orderedPropertyAttributesList = new ArrayList();
foreach (PropertyDescriptor oProp in baseProps)
{

PropertyAttributes propertyAttributes = GetPropertyAttributes(oProp, value);
if (propertyAttributes.IsBrowsable && propertyAttributes.Category == "\rMyFilteredProperties")
{
orderedPropertyAttributesList.Add(propertyAttributes);
deluxeProps.Add(
new PropertyDescriptorEx(oProp, propertyAttributes));
}

}

orderedPropertyAttributesList.Sort();

...
... subsecuent code removed....

Regards

[CFQüeb]

Tabas  Friday, November 24, 2006 5:44 PM
Hi
I have followed the steps you have written and i am able to filter based categories and display name etc.. but i have an issue with 'Design' category even if i filter the' Design' Caterory it still appears in the propertygrid with the "Locked" property .take example the Name property inside Design Category is getting filtered automagically when you filter the Design Caterory but the 'Locked' property is not gettting filtered, i tried to filter based on Display Name but no success during debugging i found property collection is not having the Locked property itself how to overcome this issue on the fly it is getting added.

thanks in advance
Regards
LongHorn7
LongHorn7  Thursday, June 14, 2007 12:31 PM

You can use google to search for other answers

Custom Search

More Threads

• Trying to Pause & Resume LogOff or ShutDown or Restart
• How can I add backgroundimage in Designer Form(DesignSurface)??
• Hello World?
• Opposite of PropertyInfo.GetGetMethod()?
• How to delete "zombie" controls in the designer
• Use my DataSet from Designer?
• how to add childmenu in designer contextmenu
• Difference between arrays and objects when referencing controls
• CustomToolboxItem class and DragDrop
• constrict properties at runtime