Discussion:
Get the ExternaProvider Control Refrence in the UITypeEditor
(too old to reply)
Ahmed Hashish
2007-09-27 12:38:29 UTC
Permalink
Dear Sir

I created a control "MyControl" that implements the IExternalProvider Class, "MyControl" should provide the property MyProperty for all other controls.



I created also an UITypeEditor class that help the user to select "MyProperty1" form a DropDownList



My Problem is I need to get a reference for MyControl in the EditValue method of the UITypeEditor because the DropDownList changes according to other property "MyProperty2" of "MyControl".



My class code like this:

public class MyControl : UserControl, System.ComponentModel.IExtenderProvider

{

……

public string MyProperty2

{

….

}



[Editor(typeof(SaudisoftMyProperty1Editor), typeof(UITypeEditor)), DefaultValue("")]

public string GetMyProperty1(Control control)

{

……

}

……



public class MyProperty1Editor : UITypeEditor

{

….

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)

{

……

MyControl sd =? //here I want to get MyControl

String M=sd.MyPropery2

……

return value;

}

…….

}

……

}
Roger Stewart
2007-09-27 13:52:46 UTC
Permalink
public override object EditValue(ITypeDescriptorContext
context, IServiceProvider provider, object value)
{
if(context == null || context.Instance == null || provider
== null)
return value;

....

MyControl ctrl = context.Instance as MyControl;
if(ctrl == null) return null;

....
}
Ahmed Hashish
2007-09-30 11:34:38 UTC
Permalink
Thanks for replay
I think you didn't got what I mean, context.Instance returns the reference of the current selected control, I need a reference for MyControl (Extender Provider) the control that provided the property the user currently editing.

best regards,
Ahmed
"Roger Stewart" <***@gmail.com> wrote in message news:***@r29g2000hsg.googlegroups.com...
public override object EditValue(ITypeDescriptorContext
context, IServiceProvider provider, object value)
{
if(context == null || context.Instance == null || provider
== null)
return value;

....

MyControl ctrl = context.Instance as MyControl;
if(ctrl == null) return null;

....
}
Ahmed Hashish
2007-10-01 12:12:58 UTC
Permalink
I found it,
ExtenderProvidedPropertyAttribute EPPA = context.PropertyDescriptor.Attributes[typeof(ExtenderProvidedPropertyAttribute)] as ExtenderProvidedPropertyAttribute;

MyControl sd = (MyControl)EPPA.Provider;

thanks
Ahmed




"Ahmed Hashish" <***@hotmail.com> wrote in message news:%***@TK2MSFTNGP05.phx.gbl...
Thanks for replay
I think you didn't got what I mean, context.Instance returns the reference of the current selected control, I need a reference for MyControl (Extender Provider) the control that provided the property the user currently editing.

best regards,
Ahmed
"Roger Stewart" <***@gmail.com> wrote in message news:***@r29g2000hsg.googlegroups.com...
public override object EditValue(ITypeDescriptorContext
context, IServiceProvider provider, object value)
{
if(context == null || context.Instance == null || provider
== null)
return value;

....

MyControl ctrl = context.Instance as MyControl;
if(ctrl == null) return null;

....
}

Ahmed Hashish
2007-09-30 12:43:26 UTC
Permalink
Thanks for replay
I think you didn't got what I mean, context.Instance returns the reference of the current selected control, I need a reference for MyControl (Extender Provider) the control that provided the property the user currently editing.

best regards,
Ahmed
"Roger Stewart" <***@gmail.com> wrote in message news:***@r29g2000hsg.googlegroups.com...
public override object EditValue(ITypeDescriptorContext
context, IServiceProvider provider, object value)
{
if(context == null || context.Instance == null || provider
== null)
return value;

....

MyControl ctrl = context.Instance as MyControl;
if(ctrl == null) return null;

....
}
Loading...