473,401 Members | 2,125 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,401 software developers and data experts.

Propertygrid disable item at runtime

Hi there,

is it possible to disable a property in the propertygrid at runtime?
Normally a property will be enabled but if i.e. the user doesn't have access
to change the property this property has to be disabled.

Is this possible?

Thx in advance.
May 21 '07 #1
2 4825
You can do this if you provide your own view on the properties. For
sub-properties, the primary list is provided by the TypeConverter, but
often (e.g. ExpandableObjectConverter) this uses values from
TypeDescriptor.GetProperties.

What you would need to do is to return some custom PropertyDescriptor
instances, usually just as a wrapper around your existing (reflective)
PropertyDescriptor, but override IsReadOnly.

If using the TypeConverter approach, then simply override
GetProperties(); if you also want TypeDescriptor to behave the same,
then in 1.1 implement ICustomTypeDescriptor, or in 2.0 consider
providing a TypeDescriptionProvider.

The source code in the following has a simple wrapper around a
PropertyDescriptor (ChainingPropertyDescriptor):
http://www.codeproject.com/csharp/Hy...Descriptor.asp

It also has various details on implementing a
TypeDescriptionProvider - just ignore the Reflection.Emit stuff if you
aren't interested.

Marc
May 21 '07 #2
Thanx Marc, going to try it !

"Marc Gravell" wrote:
You can do this if you provide your own view on the properties. For
sub-properties, the primary list is provided by the TypeConverter, but
often (e.g. ExpandableObjectConverter) this uses values from
TypeDescriptor.GetProperties.

What you would need to do is to return some custom PropertyDescriptor
instances, usually just as a wrapper around your existing (reflective)
PropertyDescriptor, but override IsReadOnly.

If using the TypeConverter approach, then simply override
GetProperties(); if you also want TypeDescriptor to behave the same,
then in 1.1 implement ICustomTypeDescriptor, or in 2.0 consider
providing a TypeDescriptionProvider.

The source code in the following has a simple wrapper around a
PropertyDescriptor (ChainingPropertyDescriptor):
http://www.codeproject.com/csharp/Hy...Descriptor.asp

It also has various details on implementing a
TypeDescriptionProvider - just ignore the Reflection.Emit stuff if you
aren't interested.

Marc
May 21 '07 #3

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

Similar topics

6
by: Terry | last post by:
I have a very basic program, but for some reason I can't get it to behave properly. What I want is a basic form with a TabControl that fills the entire form. The tab control should have 4 tabs...
1
by: newbie | last post by:
Hello, I am using a propertygrid to allow users to edit\create objects at runtime, that can update records in a database. There are certain properties (fields) that I wish to display as...
1
by: ANDRES BECERRA | last post by:
Herfried K. Wagner was kind enough to point me to the PropertyGrid control http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformspropertygridclasstopic.asp I have found a few...
1
by: Chris Dunaway | last post by:
I have a legacy application that I need to build a Windows Forms application to interface with it. The legacy application keeps its configuration information in INI style files. I wish to use a...
7
by: ljlevend | last post by:
I want to set PropertyGrid.SelectedGridItem to the first item that is displayed in a PropertyGrid. Note that the first item that is displayed depends on the value of PropertyGrid.PropertySort. ...
0
by: James Arnold | last post by:
Is it possible to reset all the GridItems within a PropertyGrid to be reset, without recursively looping through each item? I know of PropertyGrid.ResetSelectedProperty, but doesn't this mean I'd...
5
by: masterej | last post by:
Developers, Is there any way to disable all checkboxes on a form? I have a form with 160 checkboxes and I want to be able to disable all of them. Is there a way I can do something like this: ...
3
by: =?Utf-8?B?U3RldmVU?= | last post by:
Is it possible to hide a row within a PropertyGrid based upon the boolean value of another row within the PropertyGrid? I am using VS2005 with .NET Frameworks 2.0. -- ----------- Thanks,...
0
by: ntabb | last post by:
Hello all, I have a class instance that I'm attaching to a propertygrid. I would like to find a way to change the "Browsable" attribute during runtime or programmatically from outside the class...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.