I have a subclass of ExpandableObjectConverter that overrides the GetStandardValues method. From the context object passed into GetStandardValues, can I get back to the PropertyGrid's SelectedObject property ?
The context object is an ITypeDescriptorContext - specifically a PropertyGridInternal.PropertyDescriptorGridEntry. That is, the "normal" property grid context object. I'm editing a sub-sub property, via the expandable object converter. In the QuickWatch window, I can see the object I want to reach via either of these expressions:
((System.Windows.Forms.PropertyGridInternal.GridEntry)(context)).OwnerGrid.SelectedObject
((System.Windows.Forms.PropertyGridInternal.GridEntry)(context)).ParentGridEntry.ParentGridEntry.Instance
but if I use those in my code I get the compile error 'System.Windows.Forms.PropertyGridInternal.GridEntry' is inaccessible due to its protection level. The help file also says don't use the PropertyGridInternal namespace, as it's just for internal use.
So, how do I obtain the PropertyGrid's SelectedObject property within GetStandardValues ? One possible hack to get at the selected object is using reflection to obtain the private OwnerGrid property:
Object selectedObject;
PropertyInfo piOwnerGrid = context.GetType().GetProperty("OwnerGrid");
Object grid = piOwnerGrid.GetValue(context, null);
if ((grid != null) && (grid is System.Windows.Forms.PropertyGrid))
selectedObject = ((PropertyGrid)grid).SelectedObject;
else
selectedObject = null;
but I'm sure I shouldn't be doing this. Is there a better way ?
Thanks,
Andy Mackie.
[2nd post - no response in Windows Forms General]