Propertygrid disable item at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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/HyperPropertyDescriptor.asp

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

Marc
 
Back
Top