Click here to Skip to main content
15,895,799 members
Articles / Programming Languages / C#
Tip/Trick

UITypeEditor: Getting information of the owner control

Rate me:
Please Sign up or sign in to vote.
2.40/5 (4 votes)
14 Jan 2010CPOL 14.4K   4   1
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.

C#
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

C#
...
    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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 4 Pin
ingvarius9-Feb-15 10:32
ingvarius9-Feb-15 10:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.