I am using the PropertyGrid control to view/edit properties of some COM
objects. The problem I am having is that a few of the COM objects have a
property or two which return E_NOTIMPL raising a NotImplementedException in
the managed world. When an object does this, the PropertyGrid doesn't
display anything (only empty window as if the SelectedObject was null).

Is there anyway to have the PropertyGrid hide the offending property, or set
the property to read only displaying the exception name in the property
value, a not hide everything from the user? Right now the PropertyGrid not
displaying anything at all is just unacceptable for me.

I've looked into inherting from PropertyGrid, but I cannot find any
methods/events which allow me to filter/modify properties when an exception
occurs.

Any input is appreciated.

Bob

Re: PropertyGrid exception handling by Bob

Bob
Tue May 24 03:38:33 CDT 2005

I've concluded this is a bug in the .NET Framework (1.0/1.1). The problem
is deep down in the Framework within this call:

System.Windows.Forms.ComponentModel.Com2Interop.Com2TypeInfoProcessor.InternalGetProperties()

While enumerating the COM object properties, if it fails to query a property
(ie the property returns E_NOTIMPL) it bails and returns no properties at
all.

Why do I say this is a bug? Because the standard implementation for .NET
objects will write the exception name out (in my case "Not implemented")
instead of completely giving up. This means if I make a .NET wrapper object
around the COM object with all the properties, everything works as expected.

This cannot be overwritten making your own PropertyGrid because the base
class PropertyGrid treats COM objects in a special manner. It uses the
System.ComponentModel.TypeDescriptor.ComNativeDescriptorHandler property to
get a IComNativeDescriptorHandler (which is obsolete in .NET 2.0 by chance).
This property is initialized during the first PropertyGrid construction (it
creates an internal ComNativeDescriptor object). This object interfaces all
that Com2Interop stuff. I've played around with wrapping the
IComNativeDescriptorHandler myself, but the internal GetProperties member
always returns zero members for the offending COM objects -- and since
Com2Interop is all internal I'd have to rewrite all of that just to hack my
way around the bug.

This is exceptionally retarded because now I am forced to write wrapper
objects for all my COM objects.

Lame.


"Bob" <nobody@nowhere.com> wrote in message
news:OwUnDfBYFHA.2884@tk2msftngp13.phx.gbl...
>I am using the PropertyGrid control to view/edit properties of some COM
>objects. The problem I am having is that a few of the COM objects have a
>property or two which return E_NOTIMPL raising a NotImplementedException in
>the managed world. When an object does this, the PropertyGrid doesn't
>display anything (only empty window as if the SelectedObject was null).
>
> Is there anyway to have the PropertyGrid hide the offending property, or
> set the property to read only displaying the exception name in the
> property value, a not hide everything from the user? Right now the
> PropertyGrid not displaying anything at all is just unacceptable for me.
>
> I've looked into inherting from PropertyGrid, but I cannot find any
> methods/events which allow me to filter/modify properties when an
> exception occurs.
>
> Any input is appreciated.
>
> Bob
>
>