Attaching an editor to a property at runtime

L

Luis Arvayo

Is there some way to attach an editor to a property of a class at runtime ?

Ex.;


public class MyClass
{

[Editor(typeof(ImageEditor),typeof(UITypeEditor)]
public int BitmapIndex
{
get {...}
set {...}
}
}

Instead of defining statically before compile time, I need to define the
editor at runtime in order to be used together with the PropertyGrid. Is tha
possible ?

Thanks
Luis A.
 
L

Luis Arvayo

Hi,

Thanks for the response and tips.
Out of curiosity, why can't you apply attributes at compile time?

This is a class which the developer (this is a tool for developers) could
want to add its own property editor in order to use together with
PropertyGrid, and I don't want to define a fixed editor. That is to say, the
point here is the customization of the editor, instead of a fixed one.

I know that in order to use the PropertyGrid with custom editors, an wrapper
could be used for this class but that will be much more work.

Thanks
Luis A.


Alexander Shirshov said:
Luis,

My guess is you need to use ICustomTypeDescriptor together with your own
class that inherit from PropertyDescriptor. PropertyDescriptor's protected
constructor allows you to pass an array of attributes for this property.
This thread might get you started:
http://discuss.develop.com/archives/wa.exe?A2=ind0502C&L=DOTNET-WINFORMS&P=R4310&I=-3

Out of curiosity, why can't you apply attributes at compile time?

HTH,
Alexander

Luis Arvayo said:
Is there some way to attach an editor to a property of a class at runtime
?

Ex.;


public class MyClass
{

[Editor(typeof(ImageEditor),typeof(UITypeEditor)]
public int BitmapIndex
{
get {...}
set {...}
}
}

Instead of defining statically before compile time, I need to define the
editor at runtime in order to be used together with the PropertyGrid. Is
tha possible ?

Thanks
Luis A.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top