views:

119

answers:

0

I need a reference to the PropertyGrid instance which has called my UITypeEditor.

If you care to know why:

I have a Control which needs to receive a delegate from a property being edited, so that the next action performed in said Control will fire the delegate with some Control-specific information. I don't want to add a reference to the Control to the edited object, or use static methods to access a "current" Control.

Edit:

Here is a fragile way to do what I want:

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
    var editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
    var editorServiceType = editorService.GetType();
    var ownerGridField = editorServiceType.GetField("ownerGrid", BindingFlags.Instance | BindingFlags.NonPublic);
    var propertyGrid = ownerGridField.GetValue(editorService) as PropertyGrid;
}