472,960 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 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 5037
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.