473,656 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 PropertyDescrip torCollection to
remove some properties??
// remove AccessibleName properties from Button properties...
//...
PropertyGrid1.S electedObject =button1;
//...
Thanks
Aug 7 '08 #1
3 5121
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 BrowsableAttrib utes property of the grid to limit visibility
(very crude).

Look at ICustomTypeDesc riptor / TypeDescription Provided 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.Componen tModel;
using System.Windows. Forms;

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

}
static class Program
{
[STAThread]
static void Main()
{
Application.Ena bleVisualStyles ();
using (Form f = new Form())
using (MyControl ctl = new MyControl())
using (PropertyGrid grid = new PropertyGrid())
{
ctl.Dock = DockStyle.Top;
grid.Dock = DockStyle.Fill;
grid.SelectedOb ject = 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=DockS tyle.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
ShouldSerialize Dock()" 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
ShouldSerialise Foo would suffice, but you don't necessarily want to do
this for every property!

If you are using the ICustomTypeDesc riptor/TypeDescription Provider
approach you can also override SouldSerializeV alue on a
PropertyDescrip tor 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
1444
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 System.Windows.Forms.UserControl and they are all showed on the propertygrid. Is there a way i can hide all these inherited properties and show only my user control's properties ?
0
1530
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 in the Propertygrid control , but i want only show m custom made properties. How can i easy hide those properties ?
2
1300
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 is available to use? I thought it was a datagrid, but I can't get the datagrid to show up like the collections properties thing. Any help would be awesome thanks! ~benny
0
942
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 the expanded items in categories as is done with PropertyGrid.SourceObject's properties when PropertyGrid.PropertySort = CategorizedAlphabetical? Thank you, Lance
0
1525
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 expand the property) and allow those values to be edited. My code is below. The grid is showing the values but they are read-only, although the other properties for the rest of my class are editable. Public Class MeshConverter
4
3299
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; fPersonSurName : String; fPersonAge : Integer; published property PersonName : String read fPersonName write fPersonName;
0
1207
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 property, delete the text within the propertygrid cell, then the default validation error window appears. I want to modify the value to zero if no value is entered. I notice that the ConvertTo/ConvertFrom methods return objects.. which Int32...
6
2767
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 interface? e.g. when selecting the control from a toolbox with controls other properties show up when the program is in design mode than in run mode.
3
2134
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 properties don't exist!!! Do I need to import something more to use all the properties of the treeview? Right now, I 've just installed .NET 2005 Thank you all
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7311
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.