473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

simple way to remove properties in propertyGrid

Hi,

I have a form with a control..(a button for example). Then the
control properties are displayed in a propertyGrid control.

Is there any simple way to remove some unwanted properties from the
propertyGrid....removing the "AccessibleName" properties by example?

Any example about how to play with the PropertyDescriptorCollection to
remove some properties??
// remove AccessibleName properties from Button properties...
//...
PropertyGrid1.SelectedObject =button1;
//...
Thanks
Aug 7 '08 #1
3 5098
The simplest way would be to re-declare the property, setting
[Browsable(false)] on the property; example below.

There are other ways you could do it (in increasing complexity):

Use the BrowsableAttributes property of the grid to limit visibility
(very crude).

Look at ICustomTypeDescriptor / TypeDescriptionProvided for providing
custom metadata for the control, omitting these ones.

Write a custom tab for the property-grid that omits them.

The first is *by far* the simplest, even if it is more work - but note
that this will affect the regular IDE as well as your PropertyGrid.

Marc

== redeclare example ==

using System;
using System.ComponentModel;
using System.Windows.Forms;

class MyControl : Control
{
[DefaultValue("")]
[Localizable(true)]
[Browsable(false)]
public new string AccessibleName
{
get { return base.AccessibleName; }
set { base.AccessibleName = value; }
}

}
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
using (Form f = new Form())
using (MyControl ctl = new MyControl())
using (PropertyGrid grid = new PropertyGrid())
{
ctl.Dock = DockStyle.Top;
grid.Dock = DockStyle.Fill;
grid.SelectedObject = ctl;
f.Controls.Add(grid);
f.Controls.Add(ctl);
Application.Run(f);
}
}
}
Aug 7 '08 #2
Thanks!...

Your example was really usefull, Now I figure out how to add new
"custom properties and remove unwanted properties into an existing
control.

When changing a property value, the value is displayed in bold...even
if its modified in the code...
by example in your code you change ctl.Dock (ctl.Dock=DockStyle.Top)
so Dock value is displayed in bold in the property grid... is there
any way to prevent this?

thanks again for your time.
Aug 7 '08 #3
Again, it depends. If you own the property, you can do things like
specifying a [DefaultValue(...)], or providing a "bool
ShouldSerializeDock()" method (a special convention recognised by the
system) to disable it - but ultimately it doesn't distinguish between
reasons, it just cares that it isn't the default value.

I suspect in this case re-declaring the Foo property and adding a
ShouldSerialiseFoo would suffice, but you don't necessarily want to do
this for every property!

If you are using the ICustomTypeDescriptor/TypeDescriptionProvider
approach you can also override SouldSerializeValue on a
PropertyDescriptor basis; I often use this approach to track changes
since the object was last committed (i.e. the pending changes) - but it
helps that I have a bespoke utility library for doing this... it isn't
something you'd want to redo from scratch regularly!

Mac
Aug 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mrVithan | last post by:
I create a user control object and show its properties through a propertygrid object in my application. It is sure that there are 100 hundred of properties inherited from...
0
by: Peter Verburgh | last post by:
Hello, I'm using PropertyGrid control to show the properties of an control. There are standard properties for each usercontrol like "Cursor, Dock ,...ect" I don't want to show this properties...
2
by: Benny Raymond | last post by:
I'm working on a program that has a treeview, and each tree node refrences a row in my database. I really like how the properties section of the collections editor looks - is this a control that...
0
by: ljlevend | last post by:
I am exposing a property as an expandable property in a PropertyGrid by assigning a System.ComponentModel.TypeConverter attribute to the property. Is there any way to have the PropertyGrid group...
0
by: movieknight | last post by:
Hi, I have a class which I am feeding to the propertygrid, and I am exposing a Mesh object from my class for the propertygrid to display. I want the propertygrid to show the values (when you...
4
by: Tugrul HELVACI | last post by:
Changing DisplayNames of my properties using PropertyGrid component, how ?? I'm using Delphi 2006 and I have a class defination like this: TPerson = class fPersonName : String;...
0
by: Sparky74 | last post by:
I have a number of Int32 properties that I want to display in a PropertyGrid control. The problem I have is that I want to be able to bypass the framework's default validation. If you have an Int32...
6
by: ajk | last post by:
Hi I was wondering how to show different properties in design and run-mode for a user control? Is it possible to do this when implementing the System.ComponentModel.ICustomTypeDescriptor...
3
by: ippo | last post by:
Hi all, I have a silly problem with treeview. I'm using .NET 2.0. I need to set the two properties treeNodeSrc - treeNodeTypeSrc at run time using C#, but in the treeViews that I define, these two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.