Click here to Skip to main content
13,558,486 members
Click here to Skip to main content
Add your own
alternative version


44 bookmarked
Posted 21 Aug 2005
Licenced CPOL

Hiding Inherited Properties from the PropertyGrid

, 21 Aug 2005
Rate this:
Please Sign up or sign in to vote.
Two techniques for hiding properties, inherited from base controls, from the PropertyGrid.


When creating a control you will normally start with the lowest common denominator base control that provides you with some base functionality. Sometimes however the control you start with may present properties to the PropertyGrid that you do not wish to expose in your new control in the Designer as they may no longer be relevant. Here we explain two ways that you can hide these properties which you may find useful.

Hiding properties from the PropertyGrid

To hide properties from the PropertyGrid is simple all you need to use is the BrowsableAttribute and set its value to false.

public int AnIntegerProperty

So, to hide an inherited property all you need to do is encapsulate that property and add the attribute.

public override string Text

Sometimes you find that you may need to add the virtual or new keyword depending on the circumstances. Now this is an easy approach, however all you are doing is adding needless code in order to get the PropertyGrid to display what you want it to display.

An alternative approach

When you create a control it is a common practice to associate a designer with the control and using a designer allows you to separate the design-time functionality of your control from the run-time. A designer has an override called PreFilterProperties that can be used to add extra attributes to the collection that has been extracted by the PropertyGrid.

using System.ComponentModel;

[ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>"),
public class MyControl : ...

public class MyControlDesigner : ...

    protected override void PreFilterProperties(
                             IDictionary properties) 
        base.PreFilterProperties (properties);
        string[] propertiesToHide = 
                     {"MyProperty", "ErrorMessage"};
        foreach(string propname in propertiesToHide)
            prop = 
                AttributeCollection runtimeAttributes = 
                // make a copy of the original attributes 
                // but make room for one extra attribute
                Attribute[] attrs = 
                   new Attribute[runtimeAttributes.Count + 1];
                runtimeAttributes.CopyTo(attrs, 0);
                attrs[runtimeAttributes.Count] = 
                                new BrowsableAttribute(false);
                prop = 
                             propname, prop.PropertyType,attrs);
                properties[propname] = prop;

By adding the names of the properties you wish to hide to the collection propertiesToHide, you now have a quick and easy way of hiding properties without writing lots of needless code. With a little extra effort you can add this code to a base designer class and add it to all your controls where required.

Known issues

It has been noted that some properties when manipulated in this way may cause issues when the control is being edited. If you have an issue then you can use the first solution in order to hide the property, an example is the Text property when using a control based on the BaseValidator. It is still being investigated if it is always the Text property or if some other issue is causing the misbehavior.


Please take the time to vote for this article and/or to comment about it on the boards below. All suggestions for improvements will be considered.


  • 22nd August, 2005 - v1
  • 25th August, 2005 - v1.1 - added known issues.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shaun Wilde
Software Developer (Senior) MYOB
Australia Australia
All articles are supplied as-is, as a howto on a particular task that worked for me in the past. None of the articles are supposed to be out-of-the-box freeware controls and nor should they be treated as such. Caveat emptor.

Now living and working in Australia, trying to be involved in the local .NET and Agile communities when I can.

I spend a good chunk of my spare time building OpenCover and maintaining PartCover both of which are Code Coverage utilities for .NET.

You may also be interested in...

Comments and Discussions

QuestionHow to use this code? Pin
Member 807586311-Nov-11 4:14
memberMember 807586311-Nov-11 4:14 
GeneralProperties Hidden From Editor Reappear After Closing/Opening Designer Window Pin
jkcarter16-Aug-07 4:51
memberjkcarter16-Aug-07 4:51 
GeneralRe: Properties Hidden From Editor Reappear After Closing/Opening Designer Window Pin
Shaun Wilde18-Aug-07 23:33
memberShaun Wilde18-Aug-07 23:33 
GeneralRe: Properties Hidden From Editor Reappear After Closing/Opening Designer Window Pin
jkcarter19-Aug-07 6:24
memberjkcarter19-Aug-07 6:24 
QuestionWhere are the properties ??? Pin
Goudax22-Apr-07 22:44
memberGoudax22-Apr-07 22:44 
AnswerRe: Where are the properties ??? Pin
Shaun Wilde22-Apr-07 23:16
memberShaun Wilde22-Apr-07 23:16 
GeneralRe: Where are the properties ??? Pin
Goudax22-Apr-07 23:21
memberGoudax22-Apr-07 23:21 
QuestionAssociating MyControlDesigner at runtime Pin
MatthewDBush19-Jun-06 20:54
memberMatthewDBush19-Jun-06 20:54 
AnswerRe: Associating MyControlDesigner at runtime Pin
Shaun Wilde20-Jun-06 8:02
memberShaun Wilde20-Jun-06 8:02 
QuestionWhere is the sample code? Pin
Blkbam23-Apr-06 8:19
memberBlkbam23-Apr-06 8:19 
AnswerRe: Where is the sample code? Pin
Shaun Wilde23-Apr-06 8:40
memberShaun Wilde23-Apr-06 8:40 
QuestionSet ControlDesigner in code? Pin
SureShot2K1-Dec-05 14:43
memberSureShot2K1-Dec-05 14:43 
AnswerRe: Set ControlDesigner in code? Pin
Shaun Wilde1-Dec-05 15:04
memberShaun Wilde1-Dec-05 15:04 
GeneralNow all we need.. Pin
Ray Cassick22-Aug-05 4:22
memberRay Cassick22-Aug-05 4:22 
GeneralRe: Now all we need.. Pin
Shaun Wilde22-Aug-05 5:10
memberShaun Wilde22-Aug-05 5:10 
GeneralRe: Now all we need.. Pin
[Marc]23-Aug-05 7:58
member[Marc]23-Aug-05 7:58 
GeneralRe: Now all we need.. Pin
Ray Cassick23-Aug-05 8:41
memberRay Cassick23-Aug-05 8:41 
GeneralRe: Now all we need.. Pin
[Marc]23-Aug-05 12:33
member[Marc]23-Aug-05 12:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180515.1 | Last Updated 22 Aug 2005
Article Copyright 2005 by Shaun Wilde
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid