65.9K
CodeProject is changing. Read more.
Home

UITypeEditor: Getting information of the owner control

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.40/5 (4 votes)

Jan 14, 2010

CPOL
viewsIcon

14759

I did some research on the System.Drawing.Design.UITypeEditor as I tried to answer this[^] C# forum thread.My task was it, to pass information (public members) from a derived label control, to a designer DropDownControl.So I created a class which inherits from UITypeEditor and overrided...

I did some research on the System.Drawing.Design.UITypeEditor as I tried to answer this[^] C# forum thread.

My task was it, to pass information (public members) from a derived label control, to a designer DropDownControl.

So I created a class which inherits from UITypeEditor and overrided the neccesary methods.

public class SelectControlEditor : UITypeEditor
...
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
...
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
...

In the EditValue method, were the DropDownControl is initialized, I was thinking of getting all my information over the object value parameter, which would force me changing the type of the concerned property. -> Bad Idea!

But then I looked a little closer at the ITypeDescriptorContext context parameter. And there I found the Instance[^] property, which holds the reference to the object which invokes the TypeDescriptor.
Casting this to the propper type enabled me to get the member information I needed. :-D

...
    Control owner = context.Instance as Control; // get the control which is the owner of your property
...

I hope this Tip is of some value for somebody.